I have two arrays of objects with the same length.
one= [ { id: 3, name: 'a'}, { id: 5, name: 'b'}, { id: 4, name: 'c'} ]; two= [ { id: 7, name: 'b'}, { id: 6, name: 'c'}, { id: 2, name: 'a'} ];
I want to sort array 'two' by name property that depends on array 'one'.
My solution is
const tempArray = []; one.forEach((x) => { tempArray.push(two.find(item => item.name === x.name));
But is there a way to do this without creating tempArray?
I mean a one line solution?
name
s via stackoverflow.com/questions/19590865/…