Convert object array to hash map, indexed by an attribute value of the Object

前端 未结 16 2553
忘掉有多难
忘掉有多难 2020-11-28 01:08

Use Case

The use case is to convert an array of objects into a hash map based on string or function provided to evaluate and use as the key in the hash map and val

16条回答
  •  情书的邮戳
    2020-11-28 01:31

    If you want to convert to the new ES6 Map do this:

    var kvArray = [['key1', 'value1'], ['key2', 'value2']];
    var myMap = new Map(kvArray);
    

    Why should you use this type of Map? Well that is up to you. Take a look at this.

提交回复
热议问题