Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Is there a map in javascript?

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces whether there is map in javascript. It is very detailed and has certain reference value. Friends who are interested must finish reading it.

There is a map method in javascript, which returns a new array and processes the elements in the order of the original array elements; the map syntax is "array.map (function (currentValue,index,arr), thisValue)".

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

Does javascript have map?

There is a map method in javascript.

Definition and usage of JavaScript Array map () method

The map () method returns a new array whose elements are the values of the original array element after calling the function.

The map () method processes the elements in the order of the original array elements.

Note: map () does not detect empty arrays. Map () does not change the original array.

Grammar

Array.map (function (currentValue,index,arr), thisValue)

Parameter description

The parameter function (currentValue, index,arr) must be a function, which is executed by every element in the array

Parameter currentValue must be the value of the current element

Index optional: index value of the current element

Arr optional: the array object to which the current element belongs

ThisValue optional: the object is used as the callback, passed to the function, and used as the value of "this".

If thisValue is omitted, or null or undefined are passed in, the this of the callback function is the global object.

Return value: returns a new array whose elements are the values of the original array element after calling the function.

Example

Each element in the array is multiplied by the value specified in the input box and returns a new array:

Var numbers = [65, 44, 12, 4]; function multiplyArrayElement (num) {return num * document.getElementById ("multiplyWith"). Value;} function myFunction () {document.getElementById ("demo") [xss_clean] = numbers.map (multiplyArrayElement);}

Running effect:

The above is all the contents of the article "is there a map in javascript?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report