Solved

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

Posted on 2006-12-01
6
370 Views
Last Modified: 2010-05-18
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
Comment
Question by:nagunpyo
6 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 200 total points
ID: 18058633
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
 
LVL 17

Assisted Solution

by:gops1
gops1 earned 100 total points
ID: 18059044
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
 
LVL 51

Assisted Solution

by:ahoffmann
ahoffmann earned 100 total points
ID: 18059390
> 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Assisted Solution

by:aescnt
aescnt earned 100 total points
ID: 18062232
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
 

Author Comment

by:nagunpyo
ID: 18063273
Thank you everyone. :-D
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 18065077
You're welcome.  Thanks for the 'A'.  Good luck
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now