Get the App
SLTechnology News&Howtos  ›  Development  › 

The method of how to use array map in JavaScript

Shulou Source: shulou.com Published: 2022-06-01 04:58:05 09月22日 Update

Editor to share with you how JavaScript uses array map methods, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Method of array map (do not use Array.Map)

Another way to implement array map is without Array.map.

Array.from can also accept the second parameter, which acts like the array's map method to process each element and put the processed value into the returned array. As follows:

Const cities = [{name: 'Paris', visited:' no'}, {name: 'Lyon', visited:' no'}, {name: 'Marseille', visited:' yes'}, {name: 'Rome', visited:' yes'}, {name: 'Milan', visited:' no'}, {name: 'Palermo', visited:' yes'}, {name: 'Genoa', visited:' yes'} {name: 'Berlin', visited:' no'}, {name: 'Hamburg', visited:' yes'}, {name: 'New York', visited:' yes'}] Const cityNames = Array.from (cities, ({name}) = > name); console.log (cityNames); / / outputs ["Paris", "Lyon", "Marseille", "Rome", "Milan", "Palermo", "Genoa", "Berlin", "Hamburg", "New York"] these are all the contents of the article "how JavaScript uses Array map". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Array method article content processing not much not use function element parameter most way more knowledge industry information information channel channel reference learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS MariaDB OPPO Reno Shulou Information Docker