Solved

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

Posted on 2006-12-01
6
369 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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…

762 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

22 Experts available now in Live!

Get 1:1 Help Now