Generation

generate functionSat, 12 Nov 2022

Sorry an array of objects by multiple keys

function sortBy(arr, key1, key2) { return arr.sort(function(a, b) { var x = a[key1]; var y = b[key2]; return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }); }

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant