Why does it print out [ ]?


#1

I know this code is right... but why is it printing out the [ ]????

var junk = ["Worn clothes","Box",1351,211]; {
console.log(junk)
}


#2

its printing the [] because you are printing junk which is of type list. Now the that's the string representation of list. To print it without the [] we have to do

console.log(junk.toString());

but you need to sanitize your code in to this

var junk = ["Worn clothes","Box",1351,211];
console.log(junk.toString());

#3

Exactly what is his code doing right now? I would have to assume there would be an error for the " { } " But I don't really understand how that's working.


#4

His code as he has put it will print this

[ 'Worn clothes', 'Box', 1351, 211 ]

but he doesn't want the [] in there.
With the way he has defined it if the data was large enough he could loose some data because the parser could halt


#5

coz you are trying to pint out an array ...it wont work .. you have to use loop

like this :smile:
var junk = ["Worn clothes","Box",1351,211];
alert(junk.length);
var i =0;
for(i=0;i< junk.length;i++){
alert(junk[i]);
}