in javascript, create Array from an iterator -


this question has answer here:

given iterator, what's best way create array?

for example,

 let map = new map(); map.set( 'key1', 'data' ); map.set( 'key2', 'more data' ); ... // now, wish have array of keys let arr = //??// map.keys()  //??// 

i lame like

 function iter2array( iter ) {   let arr = new array();   for( let e in iter ) arr.push(e);   return arr; } 

but there has better way.

array.from(map.keys()) // ['key1', 'key2'] 

the array.from() method creates new array instance array-like or iterable object.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -