+ 2

What does new Map do and why is the output 1?

let arr = [1, 1, 5, 5, 6, 7, 6]; let map = new Map([arr, arr]); console.log(map.size); And why is the output also 1 when having new Map ([arr]); instead of ([arr, arr])? https://code.sololearn.com/Wf8YLS1bp06u/?ref=app

20th Apr 2018, 11:55 AM
Miro
Miro - avatar
1 Answer
+ 2
ES6 Map is an associative array so the data in map stores like that 'key' => 'value' Example: var map = new Map([['key1', 'value1'], ['key2', 'value2']]);
20th Apr 2018, 2:48 PM
Sergey Vishnevsky
Sergey Vishnevsky - avatar