How to remove element from array

Tuesday 09/08/2022

·1 min read
Share:
  • we can change the length of the array
const arr = [1,2,3,4]
arr.length = 2 // [1,2]
  • Array.pop() - will remove the last element and return it
  • Array.shift() - will remove the first element and return it
  • Array.splice()
const arr = [1,2,3,4]
arr.splice(1,1) // [1,3,4]

There are some other methods, this is only the basics.

Share:
VA

Vadim Alakhverdov

Software developer writing about JavaScript, web development, and developer tools.

Related Posts