Issue
I have some data which I need to sort using the first column of each object.
The project uses Angular / Typescript but it's still JS.
Here's how the data looks:
[
{
time: 1000.189,
other: 100
},
{
time: 1023.189 ,
other: 105
},
{
time: 999.189,
other: 100
}
]
So the above should look like this:
[
{
time: 999.189,
other: 100
},
{
time: 1000.189,
other: 100
},
{
time: 1023.189,
other: "105
}
]
How can I do this?
Solution
const array = [
{
time: 1000.189,
other: 100
},
{
time: 1023.189 ,
other: 105
},
{
time: 999.189,
other: 100
}
]
const result = array.sort((a, b) => a.time - b.time);
console.log(result);
result = [ { time: 999.189, other: 100 }, { time: 1000.189, other: 100 }, { time: 1023.189 , other: 105 }, ]
this works in Angular/Javascript
Answered By - LocoBE
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.