Question: I have an array of objects

```
array = [
    {id: 5, name: "Helen", age: 20}, 
    {id: 15, name: "Lucy", age: 30}, 
    {id:7, name: "Carlos", age: 1}
]

```

Then I have a similar array sorted differently

```
arraySorted = [        
    {id: 15, name: "Lucy", age: 2}, 
    {id: 5, name: "Lara", age: 11}, 
    {id:7, name: "Carlos", age: 10}
]

```

The ids of the objects on both arrays will always match, the rest of the properties may or may not.

What I need is sorting the array in the same `id` order as `arraySorted`.

(it can be also done on plain `JavaScript`, `lodash` is not necessary but maybe it will be useful)

Answer: 
Rather than `sort`, use `map`, `find` and `Object.assign` instead

```
arraySorted.map( s => Object.assign( s, array.find( t => t.id == s.id ) ) );

```

**Demo**

```js
var array = [{
    id: 5,
    name: "Helen",
    age: 20
  },
  {
    id: 15,
    name: "Lucy",
    age: 30
  },
  {
    id: 7,
    name: "Carlos",
    age: 1
  }
];
var arraySorted = [{
    id: 15,
    name: "Lucy",
    age: 2
  },
  {
    id: 5,
    name: "Lara",
    age: 11
  },
  {
    id: 7,
    name: "Carlos",
    age: 10
  }
];
array = arraySorted.map(s => Object.assign(s, array.find(t => t.id == s.id)));

console.log(array);
```
You can use `Map` to sort your array:

```js
let a1 = [{id: 5, name: "Helen", age: 20}, {id: 15, name: "Lucy", age: 30}, {id:7, name: "Carlos", age: 1}],
    a2 = [{id: 15, name: "Lucy", age: 2}, {id: 5, name: "Lara", age: 11}, {id:7, name: "Carlos", age: 10}];

let map = ((m) => (
             a2.forEach(({id}) => m.set(id, a1.find(o => o.id === id))), m
          ))(new Map());

let result = [...map.values()];

console.log(result);
```

```css
.as-console-wrapper { max-height: 100% !important; top: 0; }
```