Javascript Array create from Map

Introduction

Array from a Map

const map = new Map([[1, 2], [2, 4], [4, 8]]);
let a = Array.from(map);
console.log(a);// [[1, 2], [2, 4], [4, 8]]

const mapper = new Map([['1', 'a'], ['2', 'b']]);
a = Array.from(mapper.values());//from   w  w w.ja v a  2 s .  com
console.log(a);// ['a', 'b'];

a = Array.from(mapper.keys());
console.log(a);// ['1', '2'];



PreviousNext

Related