I have an array of objects like this and would like to re-order with another array of objects. I have tried using indexOf but am possible confusing my syntax as the array fails to re-order. I have read similar threas but haven't been able to apply those solutions to my problem. Here is code:
const task = [
{'title':1.1 , 'description': 'task description here' },
{'title':1.2 , 'description': 'task description here' },
{'title':1.3 , 'description': 'task description here' },
{'title':1.4 , 'description': 'task description here' }
];
var taskSort = [
{'title':1.2 },
{'title':1.4 },
{'title':1.3 },
{'title':1.1 }
];
task.sort(function(a, b) {
return taskSort.indexOf(a.title) - taskSort.indexOf(b.title); \\have tried many variations of this line
});
console.clear();
console.log(task);
Many thanks in advance!