• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 380
  • Last Modified:

Property set, {n1:v1, n2:v2}

I sometimes see names and values are paired like {name1:value1, name2:value2}.
Is there a name for this kind of grouping?
And are there any tutorials or articles that I can read about this?
Like those cover tips, tricks, scoping issues or things like that?
0
nagunpyo
Asked:
nagunpyo
4 Solutions
 
HonorGodCommented:
An associated array, sometimes called a hash.

It may be a literal associative array, e.g.,

  var  pairs = { 'Sun' : 0, 'Mon' : 1, 'Tue' : 2, 'Wed' : 3, 'Thu' : 4, 'Fri' : 5, 'Sat' : 6 };

  To access a value, use the name as an index into the array:

  var here = pairs[ 'Mon' ];
0
 
gops1Commented:
In general they are many a times it is associated to HashMap in Java since both of them work on key value pair. Here a value is identified with its key and not on row column address as we do in a normal array. If we take Honor's example

var  pairs = { 'Sun' : 0, 'Mon' : 1, 'Tue' : 2, 'Wed' : 3, 'Thu' : 4, 'Fri' : 5, 'Sat' : 6 };

'Sun', 'Mon' etc are the keys and what comes after ":" are the values, therefore to pick a value, it should be identified by its key:

alert(pairs[ 'Mon' ]);

this will alert "1"
0
 
ahoffmannCommented:
> Is there a name for this kind of grouping?
object literals
this is ECMAScript standard (v3 IIRC), and used in JavaScript since 1.2
it's mainly used for initialising objects
JSON makes heavy use of this.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aescntCommented:
Go check www.json.org.

JSON stands for JavaScript Object Notation, which is JS's syntax for doing name/value pairs and arrays.
  { animals: ["duck", "cow"], dog: "bark", dogCount: 55 }

By the way, what the website JSON.org is about is that JS's object notation syntax is very simple and effective, that it can even be used outside JavaScript as, say, a replacement for XML :)
0
 
nagunpyoAuthor Commented:
Thank you everyone. :-D
0
 
HonorGodCommented:
You're welcome.  Thanks for the 'A'.  Good luck
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now