Deleting Particular Data From A Json Object Using JavaScript
I am using titanium for developing Android application. I want to delete some data from json object. My json object given below: {'feeds': [ {'username':'abc','user':'abc','fee
Solution 1:
You are using splice to properly remove an element from a javascript array:
json.feeds.splice(0,1)
Using the code you've provided it will look like:
(function(){
var json = {
"feeds": [
{"username":"abc","user":"abc","feed":{"description":"dss","id":660,"user_id":1}},
{"username":"bcd","user":"bcd","feed":{"description":"dddd","id":659,"user_id":1}}
]
};
json.feeds.splice(0,1);
console.log(json.feeds); // just to check that "feeds" contains only a single element
})();
Solution 2:
- Parse the JSON into a JavaScript data structure
- Use splice to remove the elements you don't want from the array
- Serialise the JavaScript objects back into JSON
Post a Comment for "Deleting Particular Data From A Json Object Using JavaScript"