Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Custom sorting inside array of array

I have an array given below, every element of this array consists of another array.

var array = [
  ['201', 'Tom', 'EES', 'California'],
  ['189', 'Charlie', 'EE', 'New Jersey'],
  ['245', 'Lisa', 'EEF', 'New Jersey'],
  ['743', 'Niall', 'EEC', 'Chicago'],
  ['653', 'Tim', 'EES', 'Miami'],
  ['333', 'Dev', 'EE', 'Washington'],
  ['333', 'Rhonda', 'EEC', 'Washington']
]

I want it to be sorted on the basis of 3rd value and in this order [EE,EES,EEC,EEF].

array should be:

[
  ['189', 'Charlie', 'EE', 'New Jersey'],
  ['333', 'Dev', 'EE', 'Washington'],
  ['201', 'Tom', 'EES', 'California'],
  ['653', 'Tim', 'EES', 'Miami'],
  ['743', 'Niall', 'EEC', 'Chicago'],
  ['333', 'Rhonda', 'EEC', 'Washington'],
  ['245', 'Lisa', 'EEF', 'New Jersey']
]

Note :- Original array will be having n no of elements, all i want is that first EE elements should come , then EES, EEC and then EEF

Thanks in advance.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

//this is my code! You can use array.sort(...) to do this


var array=[['201','Tom','EES','California'],['189','Charlie','EE','New Jersey'],
['245','Lisa','EEF','New Jersey'],['743','Niall','EEC','Chicago'],['653','Tim','EES','Miami'],
['333','Dev','EE','Washington'],['333','Rhonda','EEC','Washington']];


let _result = array.sort(
    function(a, b){
        if (a[2].toLowerCase() < b[2].toLowerCase()) return -1;
            if (a[2].toLowerCase() > b[2].toLowerCase()) return 1;
            return 0;
    }

)

console.log(_result);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!