I have an array with key-value pairs, array columns are id and name. I want to sort this array by id.
The id column value is of type string type but I want to sort them as numeric values also should work on IE
Here is my code:
var items = [{
"id": "165",
"name": "a"
},
{
"id": "236",
"name": "c"
},
{
"id": "376",
"name": "b"
},
{
"id": "253",
"name": "f"
},
{
"id": "235",
"name": "e"
},
{
"id": "24",
"name": "d"
},
{
"id": "26",
"name": "d"
}
];
console.log(items.sort((a, b) => Number(a.ID) - Number(b.ID)))
Though the order does change it doesn't change as expected also in IE an error is thrown.