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

192
Views
array every() with includes() issues

Hey people so i've spent a bit too much time trying to find a solution for this and I'd like to know if anyone can help me.

So the problem is, I have 2 arrays, first one with multiple words from an address and another one I built with word I entered in an input, it is returning true if I put the exact same word in the input as it is in the string array but I would like it to return true if it partially match too, for example I have "CENTER" and "RACHEL" in the array of string if I write "CEN EL in the input because it would partially match 2 of the array elements

here's the code i've been trying to put together

        function checker(arr, words) {
            return words.every(v => arr.includes(v));
        }

        this.shippingAddress.forEach(address => {
            const stringBuild = `${address.name} ${address.display_address} ${address.phone}`;
            const arrayString = stringBuild.split(' ');
            if (checker(arrayString, words)) {
                _results.push(address);
            }
        });

An example of input would be for the array arrayString:

[
    0: "CENTER"
    1: "MANIKI"
    2: "BRUCHESI"
    3: "2225,"
    4: ""
    5: "STREET"
    6: "RACHEL"
    7: "EAST,"
    8: "CITY"
    9: "STUFF,"
    10: "STUFF"
    11: "STUFF"
    12: "STUFF"
    13: "STUFF"
]

for the array words:

[
    0: "CEN"
    1: "EL"
    
]

and the output would be true because CEN and EL passing in the checker would be included in the first array but it only work if I put the full words in

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

0

If I understand correctly, you want to return true if every word in the array is partially (or totally) matched?

For every word that must be matched, I would test the array of typed words, and see if at least one of the typed words partially matches the target. I'd use a regex, and also make it case-insensitive with "i" :

const checkArray = ["center","rachel"];

const isOK = (typedWords) => checkArray.every( word1 => typedWords.some( word2 => new RegExp(word2, "i").test(word1)))

console.log(isOK([ "ent" , "rac" ]))
console.log(isOK([ "AaAa" , "BbBb" ]))

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!