JSON find in JavaScript
Posted
by zapping
on Stack Overflow
See other posts from Stack Overflow
or by zapping
Published on 2009-12-22T12:43:22Z
Indexed on
2010/03/25
2:53 UTC
Read the original article
Hit count: 393
Is there a better way other than looping to find data in JSON? It's for edit and delete.
for(var k in objJsonResp) {
if (objJsonResp[k].txtId == id) {
if (action == 'delete') {
objJsonResp.splice(k,1);
} else {
objJsonResp[k] = newVal;
}
break;
}
}
The data is arranged as list of maps. Like:
[{id:value, pId:value, cId:value,...}, {id:value, pId:value, cId:value}, ...]
© Stack Overflow or respective owner