In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail what is the use of the map () method in es6. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
In es6, the map () method is used to process each element in the array by calling the specified callback function and return the array containing the results; the syntax "array.map (function callbackfn (value, index, array), thisArg);".
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
The JavaScript map () method calls the specified callback function on each element of the array and returns the array containing the results.
Array.map (function callbackfn (value, index, array), thisArg)
Function callbackfn (value, index, array): a callback function that accepts up to three parameters:
Value: the value of the array element.
Index: a numeric index of array elements.
Array: the array object that contains this element.
The map () method returns a new array where each element is the callback function return value of the associated original array element. For each element in the array, the map () method calls the callbackfn function once (in ascending indexing order) and does not call the callback function for the missing elements in the array.
Except for array objects, the map () method can be used by any object that has a length property and has an indexed property name, such as an Arguments parameter object.
Let's take a look at the code example:
Example 1: double the values of all elements (that is, multiply by 2)
Var a = [30 value 40 50]; function f (value) {return value*2;} var a1=a.map (f); console.log (A1)
Output result:
Example 2: using JavaScript built-in methods as callback functions
Var a = [9,16]; var A1 = a.map (Math.sqrt); console.log (A1); / / 3mem4
Output result:
This is the end of the article on "what is the use of the map () method in es6". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.