GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise
  • Introduction3 min read
  • Variables5 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — JavaScript Array Methods - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • JS Tutorial
  • Web Tutorial
  • A to Z Guide
  • Projects
  • OOP
  • DOM
  • Set
  • Map
  • Math
  • Number
  • Boolean
  • Exercise

JavaScript Array Methods

Last Updated : 9 Oct, 2026

JavaScript array methods are built-in methods used to add, remove, search, sort, and transform array elements. They make it easier to work with collections of data without writing lengthy loops.

1. Array Properties and Conversion Methods

length

The length property returns the number of elements in an array.

JavaScript
let arr = [10, 20, 30, 40];
console.log(arr.length);

toString()

The toString() method converts an array into a comma-separated string.

JavaScript
let arr = [10, 20, 30];
console.log(arr.toString());

join()

The join() method combines array elements into a string using the specified separator.

JavaScript
let arr = ["HTML", "CSS", "JavaScript"];
console.log(arr.join(" - "));

2. Adding and Removing Elements

push()

The push() method adds one or more elements to the end of an array and returns its new length.

JavaScript
let arr = [10, 20];
arr.push(30);
console.log(arr);

pop()

The pop() method removes and returns the last element of an array.

JavaScript
let arr = [10, 20, 30];
console.log(arr.pop()); 
console.log(arr); 

unshift()

The unshift() method adds one or more elements to the beginning of an array.

JavaScript
let arr = [20, 30];
arr.unshift(10);
console.log(arr);

shift()

The shift() method removes and returns the first element of an array.

JavaScript
let arr = [10, 20, 30];
console.log(arr.shift()); 
console.log(arr);

3. Combining and Extracting Arrays

concat()

The concat() method combines two or more arrays and returns a new array.

JavaScript
let a = [1, 2], b = [3, 4];
console.log(a.concat(b));

slice()

The slice() method returns a shallow copy of a selected portion of an array without modifying the original array.

JavaScript
let arr = [10, 20, 30, 40];
console.log(arr.slice(1, 3));

splice()

The splice() method adds, removes, or replaces elements in an array and modifies the original array.

JavaScript
let arr = [10, 20, 30];
arr.splice(1, 1, 25);
console.log(arr);

flat()

The flat() method creates a new array by flattening nested arrays to the specified depth. Its default depth is 1.

JavaScript
let arr = [1, [2, [3, 4]]];
console.log(arr.flat(2));

flatMap()

The flatMap() method maps each element and flattens the result by one level.

JavaScript
let arr = [1, 2, 3];
console.log(arr.flatMap(x => [x, x * 2]));

4. Transforming and Iterating Over Arrays

map()

The map() method creates a new array by applying a callback function to every element.

JavaScript
let arr = [1, 2, 3];
console.log(arr.map(x => x * 2));

forEach()

The forEach() method executes a callback function for each array element. It does not return a new array.

JavaScript
let arr = [10, 20, 30];
arr.forEach(x => console.log(x));

filter()

The filter() method creates a new array containing elements that satisfy a specified condition.

JavaScript
let arr = [10, 15, 20, 25];
console.log(arr.filter(x => x > 15));

5. Searching and Checking Elements

includes()

The includes() method checks whether an array contains a specified value and returns true or false.

JavaScript
let arr = [10, 20, 30];
console.log(arr.includes(20));

find()

The find() method returns the first element that satisfies a condition. It returns undefined if no element matches.

JavaScript
let arr = [10, 20, 30, 40];
console.log(arr.find(x => x > 20));

findIndex()

The findIndex() method returns the index of the first element that satisfies a condition, or -1 if none matches.

JavaScript
let arr = [10, 20, 30, 40];
console.log(arr.findIndex(x => x > 20));

some()

The some() method checks whether at least one array element satisfies a condition.

JavaScript
let arr = [10, 20, 30];
console.log(arr.some(x => x > 25));

every()

The every() method checks whether all array elements satisfy a condition.

JavaScript
let arr = [10, 20, 30];
console.log(arr.every(x => x > 5));

6. Processing and Modifying Arrays

reduce()

The reduce() method processes array elements to produce a single accumulated result.

JavaScript
let arr = [10, 20, 30];
console.log(arr.reduce((sum, x) => sum + x, 0));

fill()

The fill() method replaces array elements with a specified value within a selected range. It modifies the original array.

JavaScript
let arr = [1, 2, 3, 4];
arr.fill(0, 1, 3);
console.log(arr);

sort()

The sort() method sorts array elements in place. Use a comparison function to sort numbers numerically.

JavaScript
let arr = [30, 5, 20, 10];
arr.sort((a, b) => a - b);
console.log(arr);

reverse()

The reverse() method reverses the order of elements in an array and modifies the original array.

JavaScript
let arr = [10, 20, 30];
arr.reverse();
console.log(arr);

values()

The values() method returns an iterator containing the array's element values.

JavaScript
let arr = ["HTML", "CSS", "JavaScript"];
console.log([...arr.values()]);

7. The delete Operator

The delete operator is a JavaScript operator, not an array method. It removes an object's property, but using it on an array element leaves a hole without changing the array's length.

JavaScript
let arr = [10, 20, 30];
delete arr[1];
console.log(arr); 
console.log(arr.length); 

For removing array elements, splice() is generally more appropriate because it also shifts the remaining elements.

Comment

Explore

    JavaScript Basics
    • Introduction3 min read
    • Variables5 min read
    • Operators4 min read
    • Control Statements4 min read
    Array & String
    • Arrays6 min read
    • Array Methods4 min read
    • String5 min read
    • String Methods8 min read
    Function & Object
    • Functions4 min read
    • Function Expression3 min read
    • Function Overloading4 min read
    • Objects4 min read
    • Constructors4 min read
    OOP
    • OOP5 min read
    • Classes & Objects4 min read
    • Access Modifiers5 min read
    • Constructor4 min read
    Asynchronous JavaScript
    • Asynchronous2 min read
    • Callbacks4 min read
    • Promises4 min read
    • Event Loop3 min read
    • Async Await Fuction3 min read
    Exception Handling
    • Error and Exceptional Handling5 min read
    • Errors Throw & Try to Catch2 min read
    • Custom Errors2 min read
    • TypeError Invalid Array.prototype.sort argument1 min read
    DOM
    • DOM8 min read
    • DOM Elements3 min read
    • Custom Events4 min read
    • Addeventlistener5 min read
    Advanced Topics
    • Closure3 min read
    • Hoisting5 min read
    • Scope4 min read
    • Higher Order Functions7 min read
    • Debugging3 min read
    Courses
    • Placement 360 Course2 min read
    • MERN Full Stack Course2 min read
    • DSA and System Design Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.