Delete values from JavaScript array -


i have 2 javascript arrays (say newvalue , oldvalue).

these 2 arrays contain common values. want delete values present in oldvalue array newvalue.

example:say newvalue has values 1,2,3,4 , oldvalue has values 2,3 want delete 2,3 newvalue , newvalue should have values 1,4

this has done in javascript.

consider new value

[ {"patentid":1, "geography":"china", "type":"utility", "assignee":"abc" }, {"patentid":2, "geography":"aus", "type":"utility", "assignee":"abc" }, {"patentid":3, "geography":"aus", "type":"utility", "assignee":"abc" }, {"patentid":4, "geography":"china", "type":"utility", "assignee":"xyz" } ]   consider old value   [{"patentid":3, "geography":"aus", "type":"utility", "assignee":"abc" }, {"patentid":4, "geography":"china", "type":"utility", "assignee":"xyz" }] 

now have remove objects patent id 3 , 4 in newvalue

if common objects (that is, o1 === o2 true), can this:

var o1 = { id: 1 }; var o2 = { id: 2 }; var o3 = { id: 3 }; var o4 = { id: 4 };  var newvalue = [o1, o2, o3, o4]; var oldvalue = [o2, o3];  newvalue = newvalue.filter(function(e) { return oldvalue.indexof(e) === -1 }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -