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

122
Views
Javascript array sorting with alphanumeric 2nd string

I want to sort the multiple elements in an array. The elements are like 123_test_site, 456_rit_kol, 65_aws_folder ....... output should be on the basis of 1st string starting character as 65_aws_folder,456_rit_kol,123_test_site. Can anyone help me.

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

0

I have a solution that might help you. My solution is like this:

const arr=['456_rit_kol', '65_aws_folder', '123_test_site',]; 

arr.sort((a, b) => {
    let input1 = a.substring(a.indexOf('_'));
    let input2 = b.substring(b.indexOf('_'));
    if(input1 < input2){
        return -1;
    }else{
        if(input1 < input2){
            return 1;
        }else{
            return 0;
        }
    }
});

console.log(arr);
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!