In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "map is not a method in es6". The content of the explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "map is not a method in es6".
Map is a method in es6; this method calls the specified callback function on each element of the array and returns the data containing the result, which is a new array with the syntax "array object .map (function callback function (value of array element, array element index, array object);".
This tutorial operating environment: windows10 system, ECMAScript version 6. 0, Dell G3 computer.
Is map a method in es6?
The map () method calls the specified callback function on each element of the array and returns the array containing the results. The specific usage is as follows:
Array.map (callbackfn [, thisArg])
Parameter description:
Array: required parameter, an array object.
Callbackfn: a function that can accept up to three arguments with required parameters. For each element in the array, the map () method calls the callbackfn function once.
ThisArg: optional parameter, an object that can be referenced by the this keyword in the callbackfn function. If thisArg is omitted, undefined is used as the this value.
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.
The syntax of the callback function is as follows:
Function callbackfn (value, index, array)
The user can declare the callback function with up to three parameters. The parameters of the callback function are described as follows:
Value: the value of the array element.
Index: a numeric index of array elements.
Array: the array object that contains this element.
Example 1
The following example maps an array using the map () method, squares the value of each element in the array, multiplies the PI value, takes the area value of the returned circle as the element value of the new array, and finally returns the new array.
Function f (radius) {var area = Math.PI * (radius * radius); return area.toFixed (0);} var a = [10lad 20je 30]; var A1 = a.map (f); console.log (A1)
Example 2
The following example uses the map () method to map an array, divides the value of each element in the array by a threshold, and then returns the new array where the callback function and threshold exist as properties of the object, demonstrating how to use the thisArg parameter in map.
Var obj = {val: 10, f: function (value) {return value% this.val;}} var a = [6Mae 12mai 25Mae 30]; var A1 = a.map (obj.f, obj); console.log (A1) Thank you for your reading. The above is the content of "map is not a method in es6". After the study of this article, I believe you have a deeper understanding of whether map is a method in es6, and the specific use needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.