I'm trying to sort the array by lname in ascending order and by moving empty values to the end.
I am able to sort in ascending order, but how to move empty values to last?
let arr = [{
name: 'z',
lname: 'first'
}, {
name: 'y',
lname: ''
}, {
name: 'a',
lname: 'third'
}]
const copy = [...arr];
copy.sort((a, b) => (a.lname > b.lname ? 1 : -1))
console.log(copy);
console.log(arr)