Here we have 2 types of variables in an array and one being an integer while the other being a string , I am trying to sort the array via alphabetical order or by the length of the string but it keeps detecting the integer over the string first.
const val=[{
x:"second",
y:2
},{
x:"first",
y:1
}];
function compare(a,b){return b.length-a.length};
val.sort(compare);
console.log(val);
lengthproperty unless explicitly defined (which is not the case here)