Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community that shares solutions with each other.

If you think you have something to add here.

you are welcome with your fresh ideas - List Articles

JavaScript - how to remove element form array by index?

0 contributions
13 points

In JavaScript it is not intuitive at first time how to remove element by index. Remove element by index operation can be achieved with Array.prototype.splice method. This article is focused on how to do it.

1. Remove element by index with Array.prototype.splice method example

// ONLINE-RUNNER:browser;

//  index:    0    1    2    3
var array = ['a', 'b', 'c', 'd'];

// removing sice 1st index , 1 element
var removedElements = array.splice(2, 1);


Output (with NodeJS):

[ 'a', 'b', 'd' ]
[ 'c' ]

Notes about Array.prototype.splice method:

  • takes as first argument index of remved element
  • takes as second argument number of removed elements - it means it is possible to remove many elements during same operation
  • modifies array by removing elements and returns them as array of removed elements


  1. Array.prototype.splice method - MDN Docs 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more