I am trying to sort this array, but it doesn't work for me. I must be doing something stupid, could someone have a look and tell me what is wrong please?
var fruits = [{
config: {
priority: 99
}
}, {
config: {
priority: 1
}
}, {
config: {
priority: 10
}
}];
document.getElementById("demo").innerHTML = JSON.stringify(fruits);
function myFunction() {
let l = fruits.sort(sort);
document.getElementById("demo").innerHTML = JSON.stringify(l);
}
function sort(item1, item2) {
return item1.config.priority < item2.config.priority;
}
<p>Click the button to sort the array.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>