over 9 years ago
Hello Reader!. If you dealing with a array full of unsorted keys then you can use some of the syntax to sort them in any order, Consider the cases below:-
- var MyArray = [
- { Entry: { Fname: 'Micky', Lname: 'Jones' }, CustomerID: 56563 },
- { Entry: { Fname: 'Carlos', Lname: 'Jacques' }, CustomerID: 56598 },
- { Entry: { Fname: 'Carlos', Lname: 'Dante' }, CustomerID: 56587 },
- { Entry: { Fname: 'Tim', Lname: 'Marley' }, CustomerID: 56593 },
- { Entry: { Fname: 'Courtney', Lname: 'Smith' }, CustomerID: 56541},
- { Entry: { Fname: 'Bob', Lname: 'Smith' }, CustomerID: 56214}
- ]
var MyArray = [ { Entry: { Fname: 'Micky', Lname: 'Jones' }, CustomerID: 56563 }, { Entry: { Fname: 'Carlos', Lname: 'Jacques' }, CustomerID: 56598 }, { Entry: { Fname: 'Carlos', Lname: 'Dante' }, CustomerID: 56587 }, { Entry: { Fname: 'Tim', Lname: 'Marley' }, CustomerID: 56593 }, { Entry: { Fname: 'Courtney', Lname: 'Smith' }, CustomerID: 56541}, { Entry: { Fname: 'Bob', Lname: 'Smith' }, CustomerID: 56214} ]
On using the sortBY(KEY) MyArray .sortBy('CustomerID');
Output
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)