Get the App
SLTechnology News&Howtos  ›  Development  › 

Is there a map in javascript?

Shulou Source: shulou.com Published: 2022-06-03 18:48:01 11月04日 Update

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!

Tags: Array element function method primitive processing parameter object content article grammar order value global interest instance boy partner effect more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Microsoft Shulou Tech Info Linux Xiaomi