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

107
Vistas
Push in array only values ​that contain a certain string

I would like only data containing a certain string to be sent from my array to another array for example

test=something
test1=something
test=testsadsad

If my array contains test= My new array will be ['something', 'testsadsad'] This is my code.

let data = Object.values(args);
        let serializedData = data.join("\n");
        let newArray = [];

        for (let i = 0; i < data.length; i++) {
            if (data[i].includes("test=") === true) {
                console.log(data[i])
                newArray.push(data[i].split("test="));
            }
        }
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can modify your logic like this

//simulated data
const data = [
  "test=something",
  "test1=something",
  "test=testsadsad",
]

let newArray = [];

for (let i = 0; i < data.length; i++) {
  //`key` is `test` and `value` is `something`
  const [key, value] = data[i].split("=") //splitted by `=`
  if (key === "test") {
    newArray.push(value);
  }
}

console.log(newArray)

about 4 years ago · Juan Pablo Isaza Denunciar

0

You are not formatting the data correctly when pushing onto the array.

let data = Object.values(args);
let newArray = [];

for (let i = 0; i < data.length; i++) {
    if (data[i].includes("test=") === true) {
        console.log(data[i])
        // Note It looks like your problem is here
        newArray.push(data[i].replace("test=", ''));
    }
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

If your input array is data then this will return the desired output:

let output = data
    .filter(item => item.includes("test="))
    .map(item => item.split("test=")[1])

This filters the array by selecting all items that include test= and then maps each result to the substring after test=.

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