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

97
Views
Compare select parts of 2 Strings
0: {Id: 1, type: dog, changeNo: '0123-123-A1', …}
1: {Id: 2, type: cat, changeNo: '0123-123-F2', …}
2: {Id: 3, type: bus, changeNo: '0456-154-E5', …}
n: {Id: n, type: n, changeNo: 'n', …}
length: n

So I'm currently learning JS and react and am trying to check an object array in the form above for the same changeNo up to the second '-'. So I'd like to know if, and how many '0123-123' there are. I figured I'd iterate over the array checking for whether either string is a subset of the other, however that would lead me into errors with almost everything as it checks the adjacent Lettering as well.

let multi: number;
    for (let i=0; i <= data.length; i++) {
        for (let j=1; j <= data.length; j++) {
            while (data[i].changeNo.indexOf(data[j].changeNo) >-1) {
                multi ++;
            }
        }
    } 
return multi-1;

Is there a way to easily compare the strings in a for while loop based on the first few elements. Or maybe a way to stop comparing once the second '-' is reached?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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!