Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
190
rated 0 times [  191] [ 1]  / answers: 1 / hits: 9998  / 4 Years ago, sun, august 16, 2020, 12:00:00

Is there like a quick way to get Javascript Map values as an array?


const map:Map<number, string> = new Map()
map.set(1, '1')
map.set(2, '2')

And then something like Array.from(map.values()) would give ['1','2'] ... I could have sworn that I've something like this...?


More From » node.js

 Answers
1

It is working fine. Array.from can take an iterable value as well.




const map = new Map;

map.set(1, '1');
map.set(2, '2');

console.log(Array.from(map.values()));




[#2874] Thursday, August 13, 2020, 4 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
blaisep

Total Points: 748
Total Questions: 95
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
blaisep questions
Wed, Dec 16, 20, 00:00, 4 Years ago
Tue, Nov 12, 19, 00:00, 5 Years ago
Mon, Nov 11, 19, 00:00, 5 Years ago
Tue, Oct 15, 19, 00:00, 5 Years ago
;