JavaScriptMarch 15, 2026

Modern JavaScript Array Methods You Should Know

Master modern array methods to write more expressive JavaScript code.

Modern JavaScript Array Methods You Should Know

Modern JavaScript provides powerful array methods. Let’s explore the essential ones.

Array.prototype.at()

javascript
const arr = [1, 2, 3, 4, 5]

arr.at(0)   // 1
arr.at(-1)  // 5 (last element)
arr.at(-2)  // 4

Array.prototype.findLast()

javascript
const numbers = [1, 2, 3, 4, 5, 4, 3]

numbers.findLast(n => n > 3)      // 4
numbers.findLastIndex(n => n > 3) // 5

Array.prototype.toSorted()

Non-mutating sort:

javascript
const original = [3, 1, 4, 1, 5]
const sorted = original.toSorted()

console.log(original) // [3, 1, 4, 1, 5]
console.log(sorted)   // [1, 1, 3, 4, 5]

Array.prototype.toReversed()

javascript
const arr = [1, 2, 3]
const reversed = arr.toReversed()

console.log(arr)      // [1, 2, 3]
console.log(reversed) // [3, 2, 1]

Array.prototype.toSpliced()

javascript
const arr = [1, 2, 3, 4, 5]
const newArr = arr.toSpliced(1, 2, 'a', 'b')

console.log(arr)    // [1, 2, 3, 4, 5]
console.log(newArr) // [1, 'a', 'b', 4, 5]

Array.prototype.with()

javascript
const arr = [1, 2, 3]
const newArr = arr.with(1, 'two')

console.log(arr)    // [1, 2, 3]
console.log(newArr) // [1, 'two', 3]

Practical Examples

javascript
// Chain methods for powerful transformations
const users = [
  { name: 'Alice', age: 30 },
  { name: 'Bob', age: 25 },
  { name: 'Charlie', age: 35 }
]

const result = users
  .filter(u => u.age >= 25)
  .toSorted((a, b) => a.age - b.age)
  .map(u => u.name)

// ['Bob', 'Alice', 'Charlie']