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

226
Views
Specific text with include() and replace() with .map() ES6

I am trying to find a logic that i could use with .map() to return the desired value.
Below are 2 variables im using

    let _replaceAttr = ['SUM', 'ARRG', 'AGG', 'ATTR', "AVG(pop)"]
    let tempData = ['AVG', 'bob', 'sop']

The logic i came with out is returning all as true, if tempData index 0 is set as AVG(pop) , this will return as false.

    result = tempData.map(el => !_replaceAttr.includes(el))
    console.log(result);

    // This logic will not apply the updated array element as it will return all as true 
    let es6 = tempData.map(w => !_replaceAttr.includes(w) != true ? w.replace(w, '...') : w)

If i were to specifically test this with traditional scripting such as

console.log('AVG(pop)'.includes('AVG') 
// This will return as false  which is correct   
// or

//******* Traditional Script ******** 
    for (let i = 0; i < tempData.length; i++) {
        let output = tempData[i]
        for (let a = 0; a < _replaceAttr.length; a++) {
            if (output.includes(_replaceAttr[a])) {
                tempData[i] = tempData[i].replace(_replaceAttr[a], '').replace('(', '').replace(')', '')
            }
        }

    }
    console.log(tempData)

The traditional script i have will return the desired output ,i was wondering . Will it be achievable to go with .map() approach on above example.

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!