Usage of Arrar.prototype.map ()

Source: Internet
Author: User

---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

callbackThe elements in the original array return a new element after the method.

currentValue

callbackThe first parameter of the array in which the element is currently passed.

index

callbackThe second parameter, the index of the element that is currently being passed in the array.

array

callbackThe third argument, called map the array of methods.

thisArgcallback 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 ()

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.