Question: I've got two arrays of objects, the difference between them is only that arrayAfter will have an element added:

```
var arrayBefore = [
  {"name":"Alan","height":"171","weight":"66"},
  {"name":"Ben","height":"182","weight":"90"}
 ];

var arrayAfter= [
  {"name":"Alan","height":"171","weight":"66"},
  {"name":"Ben","height":"182","weight":"90"},
  {"name":"Chris","height":"163","weight":"71"}
 ];

```

"name" is always unique!

How can I find out which one is the element that has been added? I've tried ending up using nested for loops, but this seems overcomplicated. 

I've also found the this nice idea:

```
var diff = $(arrayAfter).not(arrayBefore ).get();

```

However, that does not seem to work on arrays of objects straight ahead.

**Is there some easy way to get the difference?**

Answer: 
If only the name indicates uniqueness, you can do:

```
//Get a list of all the names in the before array
var beforeNames = arrayBefore.map(function(person) { return person.name });

//Filter the after array to only contain names not contained in the before array
var uniqueObjects = arrayAfter.filter(function(person) {
    return beforeNames.indexOf(person.name) === -1;
});

console.log(uniqueObjects); //[{"name":"Chris","height":"163","weight":"71"}]

```

Demo: <http://jsfiddle.net/tehgc8L5/>
You can use [Array.prototype.filter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) and filter out those elements in the previous array.

```
var differences = arrayAfter.filter(function(el) {
  return arrayBefore.indexOf(el) === -1;
});

```