Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any key/value pair structure in JavaScript?

Tags:

javascript

I want to store information like:

Pseudo-Code

array(manager) = {"Prateek","Rudresh","Prashant"};
array(employee) = {"namit","amit","sushil"};
array(hr) = {"priya","seema","nakul"};

What kind of data structure can I use?

like image 609
sushil bharwani Avatar asked Jul 21 '11 05:07

sushil bharwani


2 Answers

You can use arrays to store list of data ; and objects for key-value


In you case, you'd probably use both :

var data = {
    'manager': ["Prateek","Rudresh","Prashant"], 
    'employee': ["namit","amit","sushil"], 
    'hr': ["priya","seema","nakul"]
};

Here, data is an object ; which contains three arrays.

like image 166
Pascal MARTIN Avatar answered Oct 25 '22 11:10

Pascal MARTIN


An object:

var myobj = {
  "manager": ["Prateek","Rudresh","Prashant"],
  "employee": ["namit","amit","sushil"],
  "hr": ["priya","seema","nakul"]
}

alert(myobj['employee'][1]); // Outputs "amit"
like image 13
Paul Avatar answered Oct 25 '22 10:10

Paul