javascript - Delete key/value pair from json array obtained from ajax response if key is found -
i fetching data 1 list in sharepoint , storing in json array pass onto function create new item in sharepoint list.the first function is:
$.ajax({ url: somesharepointlisturl, type: "get", headers: {"accept": "application/json;odata=verbose"}, success: function (data) { var array = new array(); (var i=0; i< data.d.results.length; i++) { var it=data.d.results[i]; array.push({ alllinks: it.alllinks, linkurl: it.linkurl.url }); } datacharts=json.stringify(array); alert(datacharts); adddefaultlinks(datacharts); }, error: function (data) { alert(data.responsejson.error); } });
the item stored in list as:[{"name":"name1","url":"http://www.name1.com"},{"name":"name2","url":"http://www.name2.com"}]
second function fetches data list after item created follows:
$.ajax({ url: url, type: "get", headers: {"accept": "application/json;odata=verbose"}, success: function (data) { var c = []; var stringdata = json.stringify(data.d.results[0].alllinks); //alert(stringdata); c.push(json.parse(stringdata)); alert(c); var xonly = c.filter(function (entry){ return entry.alllinks != x; }); alert(xonly); }, error: function() { alert('fail'); } });
i need match if value exists in newly created list item.if yes delete eg lin. value of c(json array) here is:[{"name":"name1","url":"http://www.name1.com"},{"name":"name2","url":"http://www.name2.com"}]
` entry.alllinks doesnt filter data here.alllinks undefined in entry.alllinks.please help
use array.findindex() find desired value inside array, , use array.splice() method remove object.
Comments
Post a Comment