Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda