There is an array of arrays:
var people = [[{name: "John", age: "15"}], [{name: "Maria", age: "26"}], [{name: "Alex", age: "9"}]]
How can I move "John" to the end of people by his age value? I'm honestly beginner in JS and looking for any help with this task
Asked
Active
Viewed 32 times
0
1 Answers
0
var people = [[{name: "John", age: 15}], [{name: "Maria", age: 26}], [{name: "Alex", age: 9}]];
people.sort((a,b) => a[0].age - b[0].age);
console.log(people);
Observations:
- John would not be at the end if sorted by age -- his age is in the middle
- You should use integers for your ages. If you don't wrap your sort function values in
parseInt
. - The array-of-one-element-arrays thing doesn't seem to make sense -- you may want to rethink that structure.

Chase
- 3,028
- 14
- 15