underscore.js - How to get remove a particular json object from an array of json objects , in node.js -
i have array of json objects, eg
var user =[ { id: 1, name: 'linto', img: 'img' }, { id: 2, name: 'shinto', img: 'img' }, { id: 3, name: 'hany', img: 'img' } ]
from this, need remove particular json object
{ id: 2, name: 'shinto', img: 'img' }.
ie output array should
[ { id: 1, name: 'linto', img: 'img' }, { id: 3, name: 'hany', img: 'img' } ]
is there function in node.js achieve ?
use delete command that.
e.g.
delete user[index]
edit: splice
command works better in case of array removes element. in case of delete null replaces deleted element.
user.splice(0,<index>);
full code :
var user =[ { id: 1, name: 'linto', img: 'img' }, { id: 2, name: 'shinto', img: 'img' }, { id: 3, name: 'hany', img: 'img' } ] alert(json.stringify(user)); user.splice(0,1); alert(json.stringify(user));
Comments
Post a Comment