I have an array stored in my local storage. It is dynamic. I'm storing the data along with an ID which gets incremented after every entry. User has an option of deleting, hence, I'm supposed to remove the corresponding element from the array. But, I want the ID to remain in ascending order. Ex:
var jsonObj = [{'id':'1','name':'Ray','email':'[email protected]'},
{'id':'2','name':'Steve','email':'[email protected]'},
{'id':'3','name':'Albert','email':'[email protected]'},
{'id':'4','name':'Christopher','email':'[email protected]'}]
I'm creating HTML divs for the above array. In case, Steve deletes his details, I want the array to be like:
var jsonObj = [{"id":1,"name":"Ray","email":"[email protected]"},
{"id":2,"name":"Albert","email":'[email protected]"},
{"id":3,"name":"Christopher","email":"[email protected]"}]
The following code doesn't work accordingly.
for (var i=0; i<jsonObj.length; i++) {
//delete function is working fine.
jsonObj[i].id--;
break;
}