array delete element by index code example

Example 1: javascript remove from array by index

//Remove specific value by index
array.splice(index, 1);

Example 2: how to remove element from array in javascript

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

Example 3: javascript remove index from array

array.splice(index, 1); // Removes one element at index

Example 4: how can i remove a specific item from an array

const items = ['a', 'b', 'c', 'd', 'e', 'f']
const i = 2
const filteredItems = items.slice(0, i).concat(items.slice(i + 1, items.length))
// ["a", "b", "d", "e", "f"]

Example 5: java script removing first three indexes

var indexToRemove = 0;
var numberToRemove = 1;

arr.splice(indexToRemove, numberToRemove);

Tags:

Cpp Example