469,626 Members | 1,529 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,626 developers. It's quick & easy.

Square brackets and what they mean in variable assignment

i.e.

var foo = [
{something: "blah", somethingelse: "blahblah"},
{something: "blah", anotherthing: "xxx"}
];

Do the "[]"'s just represent an array? and the "{}"'s represent a named
value array?
Nov 27 '06 #1
1 2640
User1014 wrote:
i.e.

var foo = [
{something: "blah", somethingelse: "blahblah"},
{something: "blah", anotherthing: "xxx"}
];

Do the "[]"'s just represent an array? and the "{}"'s represent a named
value array?
Yes. You are initialising foo with an array literal, where each element
of the array is an object literal. It is preferred to using new Array()
or new Object() and is called an initialiser, e.g.:

var anArray = [];
var anObject = {};

Incidentally, what you are calling a 'named value array' is a plain
javascript Object. Javascript arrays are objects too, but they have
some special properties and methods.
--
Rob
Nov 27 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by cplusplus | last post: by
100 posts views Thread by E. Robert Tisdale | last post: by
5 posts views Thread by Daniel Klein | last post: by
669 posts views Thread by Xah Lee | last post: by
3 posts views Thread by balakrishnan.dinesh | last post: by
3 posts views Thread by Grande News | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.