By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,057 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

array problem

100+
P: 107
why cant i do this:

for (var i=0;i < 100; i++)
myarr[] = "foo" + i;


i have to use myarr[i] = blah

any way around this?
Feb 5 '08 #1
Share this Question
Share on Google+
3 Replies


100+
P: 428
myarr[] doesn't refer to anything,
and myarr[i] does.

This is another way to populate an array of consecutive integers-
var myarr=[];
while(myarr.length<100) myarr.push('foo'+myarr.length)
Feb 5 '08 #2

100+
P: 107
myarr[] doesn't refer to anything,
and myarr[i] does.

This is another way to populate an array of consecutive integers-
var myarr=[];
while(myarr.length<100) myarr.push('foo'+myarr.length)

oh ok, so i was hoping myarr[] = "foo"; would just add to the end of the array like php, but i can just use push instead then (doesnt matter if its at the end or not, just in the array is fine)
Feb 6 '08 #3

100+
P: 428
push adds its arguments to the end of the array.
Feb 6 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.