I have a list of items that I am being iterated over it and doing some stuff. So what I wanted is to have store some dynamic values on the fly as key:value pairs. I am actually new to Java Script and I am not sure this a good way and I appreciate if anyone can share any other possible ways. Here is what I did:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var map = new Object(); | |
for ( var i = 0; i < data.length; i++) { | |
//what ever your logic goes here | |
map[data[i].key] = {val: data[i].value}; //map keys to values | |
console.log(data[i].key + ": " + (map[data[i].key]).val); | |
} |
Output:
key1: val1
key2: val2
.
.
keyn: valn
Correct me if this is wrong or not the efficient way!
No comments:
Post a Comment