xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

ES6 Map to Array

function differentSymbolsNaive(str) {
  //  write code here.
  const map = new Map();
  const arr = Array.from(str);
  for (const item of arr) {
    if(!map.has(item)) {
      map.set(item, item);
    }
  }
  return [...map].length;
  // return [...map.keys()].length;
}

Array.from


const map = new Map().set('a', 1).set('b', 2);

const array = Array.from(map, ([name, value]) => ({ name, value }));

console.log(array);

https://stackoverflow.com/questions/56795743/how-to-convert-map-to-array-of-object

https://stackoverflow.com/questions/35341696/how-to-convert-map-keys-to-array/35341828

https://stackoverflow.com/questions/8763125/get-array-of-objects-keys

refs



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!


原文地址:https://www.cnblogs.com/xgqfrms/p/14182098.html