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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With