You can map the array values without using the map method by just using the from method of Array. Let’s map city names from Countries array:
1 2 3 4 5 6 7 8 9 10 11 12 13 | const countries = [ { name: 'India', capital: 'Delhi' }, { name: 'US', capital: 'Washington' }, { name: 'Russia', capital: 'Moscow' }, { name: 'Singapore', capital: 'Singapore' }, { name: 'China', capital: 'Beijing' }, { name: 'France', capital: 'Paris' }, ]; const cityNames = Array.from(countries, ({ capital}) => capital); // ['Delhi, 'Washington', 'Moscow', 'Singapore', 'Beijing', 'Paris'] console.log(cityNames); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.