Here, I am deleting the particular Array [2] from the json object. But, what I am seeing in console is -- array values are deleted but it remains in the idx when I checked using $.each
in jquery after deleted. So, How to delete the entire array object in a correct way?
var obj = {
equipments:'first',
messages:['msg1','msg2','msg3'],
}
console.log(obj);
$.each(obj.messages, function (idx, obj) {
alert("before deleted index value" +idx);
});
obj1 = obj;
if(obj1["equipments"] == 'first' ) {
delete obj1.messages[2];
}
console.log(obj1);
$.each(obj1.messages, function (idx, obj1) {
alert("after deleted but index remains same" +idx);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>