json - How to delete a specific element from an array of JavaScript objects? -
i receiving json output php file, number of objects so:
[ { "home_content" : "nam feugiat sem diam, ut fermentum orci hendrerit sit amet.", "home_id" : 2, "home_img" : "tech.png", "home_title" : "latest technologies development" }, { "home_content" : "לורם לורם", "home_id" : 239, "home_img" : "http://placehold.it/400", "home_title" : "שוק פירות וירקות" }, { "home_content" : "new item content", "home_id" : 259, "home_img" : "http://www.placehold.it/100", "home_title" : "new home item" } ]
in app want delete object, there way recieve position home_id
? or let me differentiate object list
what have there array of objects, can loop through array until find 1 desired home_id
:
var index; (index = 0; index < array.length; ++index) { if (array[index].home_id === 2) { array.splice(index, 1); // removes entry break; // exits loop } }
Comments
Post a Comment