I was looking online to see various ways to delete a record from object and to replace the id of the record deleted by the next record available, meaning The usage of delete
operator in JavaScript does not the delete the record id associated with it. say I have an Object:
obj= {
0:{},
1:{},
2:{},
3:{}
}
and I want to delete a record from that object, I do:
delete obj[1]
and it deletes the record but when I console.log(obj)
I see:
obj= {
0:{},
2:{},
3:{}
}
I know one way could be to convert this object into an array, then delete the element from array and convert it back to an object. If I have to avoid all this conversion, is there a way in JavaScript object when we delete the record, the obj returns as the following when we delete the obj[1]
record:
obj= {
0:{},
1:{},
2:{}
}
instead
obj= {
0:{},
2:{},
3:{}
}