An Introduction to JavaScript Array Methods

Shohan Shabbir
4 min readMay 5, 2021

--

JavaScript is a popular language today. JavaScript was created in 1995 by Brendan Eich while he was an engineer at Netscape. JavaScript was first released with Netscape 2 early in 1996. It was originally called LiveScript, but later it was named JavaScript because of the popularity of the Java language itself though these two languages have fewer similarities.

In JavaScript, an array is a single variable that is used to store different elements. It is often used when we want to store the list of elements and access them by a single variable. Unlike most languages where an array is a reference to multiple variables, in JavaScript array is a single variable that stores multiple elements. Array Example: Var house [“1BHK”, “2BHK”, “3BHK”]. There are many array methods in JavaScript. Let’s know about some of them

Concat()

The concat() method is a very popular one in javascript array methods. concat() method is used to merge two arrays together. This method does not change the existing arrays but returns a new array.

every()

The every() method is used to check whether all the elements present in the array pass the given condition. It returns a boolean value. If all the elements in the array pass the test it returns true or it returns false.

fill()

The fill() method changes the elements in an array as per the given instruction. It changes the whole array and then returns a modified version of the array. It starts from index 0 and ends at the last index (array.length). Syntax

fill(value)
fill(value, start)
fill(value, start, end)

filter()

The filter() method creates a new array with all the elements that are passed the given condition in the function. It calls a call back function for every element in the array and then makes a new array with those elements that can pass the given condition. Basically, it filters out the elements that the function wants.

find()

This method returns the first element in the provided array that satisfies the given condition in the function. The find method executes the callback function once for each index of the array until the function returns a true value. otherwise, it returns undefined.

findIndex()

This method returns the index of the first element that satisfies the provided condition in the function. It calls to call back function for every element in the array and if the condition is satisfied then it returns the index of that element otherwise it returns -1

join()

This join method creates and returns a new string by contacting all the elements in an array or returns an array-like object. Basically, it joins all the elements together

join()
join(separator

map()

This method mainly callback a function once for each element in an array, in order, and constructs a new array from the results. The callback is triggered only for indexes of the array which have assigned values

slice()

The slice() method returns a new array containing a portion of the array on which it is implemented. The original remains unchanged. It accepts two parameters one is start index and another one end index

pop()

The pop() method removes the last element of an array and then returns the value. By doing so pop() method changes the length of the array

--

--

Shohan Shabbir
Shohan Shabbir

Written by Shohan Shabbir

An Enthusiastic full-stack developer with a passion for developing and designing different types of web applications and work across different technologies.

No responses yet