Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Want to store array as value in javascript map [closed]

I want to create a map where key is string and value is an array Like below .How to store a array with key as string in map

fruits : apple,orange,pineapple
countries:usa,uk,india,australia
cities:frankfurt,berlin,moscow

var map = new Object(); 

map['fruits'] = myObj1;
map['countries'] = myObj2;
map['cities'] = myObj2;

function get(k) {
    return map[k];
}
like image 699
javascriptlearner Avatar asked Dec 18 '14 08:12

javascriptlearner


1 Answers

you can use map() collection in javascript

var myObj1 =[" apple","orange","pineapple"]

var map = new Map();
map.set("fruits", myObj1);  // to set the value using key
alert(map.get("fruits"));   // to get the value 

DEMO

like image 193
Balachandran Avatar answered Oct 15 '22 06:10

Balachandran