This fiddle shows how to grab the elements not in an array based upon the value of a key 9in my case id
).
This solution was taken from here: Difference between two array of objects in JavaScript
Before finding that solution I attempted to use simple for loops to end up with an array that consisted ONLY of objects in a
but NOT in b
.
Could someone provide the solution without using javascripts Array.prototype.filter
function?
Edit: In my case I specifically wanted to handle a case an array b
is always a subset of an array a
.
I was running into trouble with a nested loop, but once I broke the inner loop out into a function I was able to grab the solution very quickly:
Unfortunately, I see why the other solution is preferable - mine won't return a true difference, only the elements in a
and not in b
, unless I concat the two returned arrays (http://jsfiddle.net/xzy9Lyr0/2/).