Sitemap

Member-only story

JavaScript Data Structure: Array

--

Press enter or click to view image in full size

Almost all programming languages natively support the array type because it is the simplest memory data structure. Arrays are also one of the most common data structures in JavaScript, offering many methods for handling stored data. In JavaScript, arrays are enhanced objects, and unlike other languages, each slot in an array can store data of any type. This means you can create an array where the first element is a string, the second is a number, and the third is an object. JavaScript provides many practical methods for arrays, and this article summarizes the commonly used array operations.

1. Array.map()

The .map() method creates a revised version of the original array. It accepts a function that iterates over all items in the array and modifies them accordingly.

Syntax

const newArray = array.map(function callback(currentValue[, index[, array]]) {
// Return new element for the new array
}[, thisArg])

The map function is used to iterate over array elements. It takes a callback function as an argument and returns a new array with the modified elements.

Parameters

  • callback (required): A function that generates new array elements. It accepts three parameters:currentValue: The current element being processed in the…

--

--

Technology changes life, research and development to build the future, detail casting quality.