I have an an array with key-value pair, 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.
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"
}
]
items.sort((a,b)=>a.id-b.id)
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"
}];
items.sort((a, b) => Number(a.id) - Number(b.id));
console.log(items);
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"
}];
// for asscending
items.sort((a, b) => Number(a.id) - Number(b.id));
console.log(items);
// for descending
items.sort((a, b) => Number(b.id) - Number(a.id));
console.log(items);
I'm using Django and Python 3. I have this in my HTML code: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> ...
I'm using Django and Python 3. I have this in my HTML code: {% for category in categories() %} <li class="c-menu__item fs-xsmall"> <a href="#" id="next-category"> ...
I'm trying to use the panResonder in my React Native app. I tried doing so using class properties instead of constructor and super(). Here is the code: export default class Deck extends Component { ...
I'm trying to use the panResonder in my React Native app. I tried doing so using class properties instead of constructor and super(). Here is the code: export default class Deck extends Component { ...
I want to customize the search displayed by Global Search Box in Dynamics Crm by applying some custom Javascript to it. Is there any way to achieve it
I want to customize the search displayed by Global Search Box in Dynamics Crm by applying some custom Javascript to it. Is there any way to achieve it
Can you please advise how can I initiate .click [or alternative] on "PressHERE" button on IE website [VBA]? I have tried calling it by classname, tagname and even Id which is not stated in the ...
Can you please advise how can I initiate .click [or alternative] on "PressHERE" button on IE website [VBA]? I have tried calling it by classname, tagname and even Id which is not stated in the ...