remove element from array object javascript code example

Example 1: remove a particular element from 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"]

Example 2: javascript remove property from object

var person = {"first_name": "Billy","last_name": "Johnson"};
delete person.last_name; //delete last_name property

Example 3: remove object from array javascript

someArray.splice(x, 1);

Tags:

Php Example