aureader
0
Q:

pop up element from specific index in array

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"]
14
let items = ['a', 'b', 'c', 'd'];
let index = items.indexOf('a')
let numberOfElementToRemove = 1;
if (index !== -1) { items.splice(index,numberOfElementToRemove)} 
1
var fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
  fruits.splice(2, 2);
  document.getElementById("demo").innerHTML = fruits;
}
0
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"]
-1

New to Communities?

Join the community