Remove an element from array JavaScript

Often times developers run into a situation where they have to remove a specific element from an Array. And with JavaScript there a quite a lot of ways to approach this. Below are some of simple and straightforward examples,

Remove from a specific location

let array = ["apple", "ball", "cow", "dog", "egg"];
const location = 1;

array.splice(location, 1);

// array ->  ["apple", "cow", "dog", "egg"];

Remove at the end

let array = ["apple", "ball", "cow", "dog", "egg"];

// array -> ["apple", "ball", "cow", "dog"]

Remove at the beginning

let array = ["apple", "ball", "cow", "dog", "egg"];

// array -> ["ball", "cow", "dog", "egg"]
Last Updated: 1/20/2020, 12:28:24 PM
Siddhartha Gudipati
I'm Sid, a designer. I write about tech, ux, life, random thoughts and also post pictures I clicked with my Sony a7iii. If you enjoy content follow me on twitter.