Answers for "array value remove in javascript"

282

javascript array remove element

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"]
Posted by: Guest on July-19-2019
1

remove a value from array js

const index = array.indexOf(item);
if (index > -1) {
	array.splice(index, 1);
}
Posted by: Guest on December-04-2020
0

how to remove a value from an array and return the new array in javascript

var arr = [1, 2, 3, 4, 5, 5, 6, 7, 8, 5, 9, 0];
    
    for( var i = 0; i < arr.length; i++){ 
                                   
        if ( arr[i] === 5) { 
            arr.splice(i, 1); 
            i--; 
        }
    }

    //=> [1, 2, 3, 4, 6, 7, 8, 9, 0]
Posted by: Guest on December-20-2020
0

remove a value to an array of javascript

var data = [1, 2, 3];

// remove a specific value
// splice(starting index, how many values to remove);
data.splice(1, 1);
// data = [1, 3];

// remove last element
data.pop();
// data = [1, 2];
Posted by: Guest on November-10-2019

Code answers related to "array value remove in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language