?
Solved

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

Posted on 2006-12-01
6
Medium Priority
?
377 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 41

Accepted Solution

by:
HonorGod earned 800 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 400 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 400 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 6

Assisted Solution

by:aescnt
aescnt earned 400 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…
Suggested Courses

777 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