Jump to content
Larry Ullman's Book Forums

Array Literal Syntax


Recommended Posts

Hello every one

 

may some one can help me in this issue. When I use Literal syntax for Array like this:

 

var name = ['name1', 'name2', 'name3', 'name4'];

alert(name[2]);

 

it return to characters in Array, but when i use it like this way:

 

 

var names = ['name1', 'name2', 'name3', 'name4'];

alert(names[2]);

 

it return to the name3 at full not just one character on it.

 

So my question is, there any point i miss to learn about this technique, or it could be problem in language ?

Link to comment
Share on other sites

yah I use Chrome, but it not only browser I use to test my script like

Safari, Opera, IE8, FireFox, and Navigator 9.

Anyway it happen with me when I use Chrome and Safari ,

Antonio Conte, Thanks dear for your comment but I already know this thing and I don't have problem with , Thanks a lot !!

HartleySan, I agree with you, maybe it could be globe in webkit browsers !! :unsure: but why i dont hear about before, anyway you too Thanks a lot for helping

Link to comment
Share on other sites

Just don't use the name "name" (or any other keyword for that matter) for a global variable name, and you'll be fine.

 

Edit: It's not surprising that you haven't heard of it. I didn't know about it either until you brought it up and I played with it a bit.

Part of the problem with browsers like Chrome and FF constantly being silently updated is that things like this get introduced with little to no documentation, or worse, little to no knowledge of this cross-browser issue by the developers themselves.

I guess some prudence always pays off. If any variable name with the exception of "name" works fine, then I guess you know it's an issue with that variable name (for whatever reason).

Link to comment
Share on other sites

 Share

×
×
  • Create New...