I have below javascript object
temp=[
{'id': 0, 'name': 'Housing', 'value': 3},
{'id': 1, 'name': 'Bank', 'value': 8},
{'id': 2, 'name': 'Entertainment', 'value': 3},
{'id': 3, 'name': 'Restaurant', 'value': 3},
{'id': 4, 'name': 'Groceries', 'value': 7}
]
I would like to remove a row based on the name field.
Example: if I invoke the function with the name 'Entertainment', I wanted that particular row to be removed and readjust ids (0,1,2,3...) All other rows should be there as is.
After the function, temp should be
temp=[
{'id': 0, 'name': 'Housing', 'value': 3},
{'id': 1, 'name': 'Bank', 'value': 8},
{'id': 2, 'name': 'Restaurant', 'value': 3},
{'id': 3, 'name': 'Groceries', 'value': 7}
]
How can I do it ?
I tried below:
function realign(tagrm)
{
temp.each(function (i, elem) {
temp[i] = {
if(temp[i][name]==tagrm)
delete temp[i]
}
}
How can i get that particular row can be removed and other rows id's are readjusted to 0,1,2,3... ?