Associative Arrays - ES6

I know that I can declare an associative "array", for example:

var myData = {
    foo: 'val1',
    bar: 'val2',
    baz: 'val3'
};

What is the standard practice of declaring associative arrays in ES6?

+4
source share
1 answer

Objects are associations of string keys and arbitrary values.

ES6 introduces maps, which are associations of arbitrary keys and arbitrary values.

var m = new Map([
  ['a', 'b'],
  [1, 2],
  [true, false]
]);
m.get('a'); // 'b'

There is no standard practice, but maps can be considered if you want to link values.

+3
source

Source: https://habr.com/ru/post/1626226/


All Articles