[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]

/prog/ - Programming

Programming board

Catalog

See 8chan's new software in development (discuss) (help out)
Please read: important information about failed Infinity Next migration
Name
Email
Subject
Comment *
File
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Embed
(replaces files and can be used instead)
Options
Password (For file and post deletion.)

Allowed file types:jpg, jpeg, gif, png, webm, mp4, pdf
Max filesize is 8 MB.
Max image dimensions are 10000 x 10000.
You may upload 1 per post.


File: 1450105938013.png (106.97 KB, 1649x494, 1649:494, 2015-12-13-130936_1649x494….png)

498667 No.3717

 
var a0 = document.getElementsByTagName("audio")[0];
var a1 = document.getElementsByTagName("audio")[1];
var a2 = document.getElementsByTagName("audio")[2];
var a3 = document.getElementsByTagName("audio")[3];

How to do this in a for loop?

cf050a No.3719

Go back to school.

Read a book.

Do any fucking beginner's tutorial.

If you are stumped on this, you really need to be reading, not asking questions on 8chan.


ad6adf No.3720

The answer: you can't do that in a for loop. Your question is focused too heavily. Step back and show more code, and this awfulness can be removed.

For example, if all you want to is frob all the audios on the page, i.e., if your code goes on to say frob(a0); frob(a1); etc., then you can do this:

var audio = document.getElementsByTagName("audio")
for (var i = 0, length = audio.length; i < length; i++) {
frob(audio[i])
}

Actually b/c JavaScript you totally can do exactly what you wrote with a for loop, assuming global scope on those vars, but I'm not going to tell you how, because it's fucking stupid.


83c502 No.3746

You don't.

You keep those things in the array.


aeef6f No.3801


#def MAGIC 69

T a[MAGIC];
// magically allocated

for (auto i = 0; i < MAGIC; ++i) {
a[i] = thingy.get("tagname")[i];
// magically copied
}




[Return][Go to top][Catalog][Post a Reply]
Delete Post [ ]
[]
[ home / board list / faq / random / create / bans / search / manage / irc ] [ ]