---restore content starts---
map()
method returns a new array that consists of the return value of each element in the original array that is called after a specified method.
Array.map (callback[, Thisarg])
Note: [] the contents of [] within the syntax represent optional parameters
callback
The elements in the original array return a new element after the method.
currentValue
callback
The first parameter of the array in which the element is currently passed.
index
callback
The second parameter, the index of the element that is currently being passed in the array.
array
callback
The third argument, called map
the array of methods.
thisArg
callback
this
The object to point to when the function is executed.
If the thisArg
parameter has a value, each time the callback
function is called, this
it points to the thisArg
object on the parameter. If omitted thisArg
参数,
或者赋值为 null
or undefined
, this is a pointer to the global object.
map
Does not modify the original array that invokes it (it can, of course, callback
change the original array at execution time).
When working with arrays using the map method, the range of array elements is determined before the first invocation of the callback method. During the execution of the map method: The newly added elements in the original array will not be accessed by callback, and if the existing elements are changed or deleted, their values passed to callback are the values of the time the map method traverses them, and the deleted elements will not be accessed.
1 <script type= ' text/javascript ' >2 var arr = [1,8,5,3,2,8 3 var arr1 = Arr.map (function 4 arr . Push (5 5 return value*3 6 }) 7 Console.log (arr1); 8 Console.log (arr); 9 </script>
here is the value of the output, you can see that the value added to the array when executing the function is not accessed [3, 9, 6, 1, 8, 5,3, 2, 8, 5, 5, 5, 5, 5, 5]
---restore content ends---
Usage of Arrar.prototype.map ()