Mapping Arrays with JavaScript

Posted by






JavaScript Array Map

JavaScript Array Map

The map() method creates a new array with the results of calling a provided function on every element in the calling array.

Here is an example of how the map() method works:

In this example, the map() method is used to apply the Math.sqrt function to each element in the numbers array, resulting in a new array roots with the square root of each number.

The syntax for the map() method is:

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

Where array is the array you want to operate on, currentValue is the value of the current element being processed, index is the index of the current element being processed, arr is the array map() was called upon, and thisValue is the value to use as this when executing the callback function.

The map() method does not change the original array and does not execute the function for array elements without values.

Overall, the map() method is a useful tool in JavaScript for performing operations on array elements and creating new arrays based on those operations.


0 0 votes
Article Rating
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
🎀 Z and P 🎀
11 months ago

maaf pak, untuk record screen video nya pakai apa ?