Question : initialize a map js
Answered by : pratham-katiyar
let map = new Map()
map['bla'] = 'blaa'
map['bla2'] = 'blaaa2'
console.log(map) // Map { bla: 'blaa', bla2: 'blaaa2' }
Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | Last Update : Thu, 18 Jun 20
Question : initialize map js
Answered by : hamza-mateen
const values = [ ["name", "John"], ["age", 30]
];
const map = new Map(values);
console.log(map);
// output
Map(2) {'name' => 'John', 'age' => 30}
Source : https://sabe.io/blog/javascript-initialize-map-values#google_vignette | Last Update : Wed, 30 Aug 23
Question : map in javascript
Answered by : vishal-4vfs6l0xobcm
let myMap = new Map()
let keyString = 'a string'
let keyObj = {}
// setting the values
myMap.set(keyString, "value associated with 'a string'")
myMap.set(keyObj, 'value associated with keyObj')
myMap.set(keyFunc, 'value associated with keyFunc')
myMap.size // 3
// getting the values
myMap.get(keyString) // "value associated with 'a string'"
myMap.get(keyObj) // "value associated with keyObj"
myMap.get(keyFunc) // "value associated with keyFunc"
Source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map | Last Update : Sun, 28 Jun 20