var myJsonObj = {"employees":[{"name":"John", "lastName":"Doe", "age": 55},{"name":"Jane", "lastName":"Doe", "age":69}]};
How can I delete myJsonObj.eployees[1] ?
Thank you :)
var myJsonObj = {"employees":[{"name":"John", "lastName":"Doe", "age": 55},{"name":"Jane", "lastName":"Doe", "age":69}]};
How can I delete myJsonObj.eployees[1] ?
Thank you :)
delete myJsonObj.employees[1];
However, this will keep the index of all the other elements. If you want to re-order the index, too, you could use this:
// store current employee #0
var tmp = myJsonObj.employees.shift();
// remove old employee #1
myJsonObj.employees.shift();
// re-add employee #0 to the start of the array
myJsonObj.employees.unshift(tmp);
Or you use simply Darin Dimitrov's splice solution (see his answer below).