I want to get values of a map and store inside a string array in typescript.
myMap= [0:'Mohit',1:'Balesh',2:'Jatin'];
arr[];
Expected Result arr['Mohit','Balesh','Jatin']
First of all, your myMap
is not valid.
It should look like this:
myMap= {0:'Mohit',1:'Balesh',2:'Jatin'};
And getting an array from it should look like this:
myArr = Object.values(myMap);
To get an array from the values in a map you can spread the map values into an array using the Javascript spread operator (...) with the values() method of map.
yourArray = [...myMap.values()]
// gives the array ['Mohit', 'Balesh', 'Jatin']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With