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

106
Views
Empuje en la matriz solo los valores que contienen una determinada cadena

Me gustaría que solo los datos que contienen una determinada cadena se envíen desde mi matriz a otra matriz, por ejemplo

 test=something test1=something test=testsadsad

Si mi matriz contiene test= Mi nueva matriz será ['algo', 'testsadsad'] Este es mi código.

 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 answers
Answer question

0

Puedes modificar tu lógica así

 //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 Report

0

No está formateando los datos correctamente al insertarlos en la matriz.

 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 Report

0

Si su matriz de entrada son data , esto devolverá la salida deseada:

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

Esto filtra la matriz seleccionando todos los elementos que incluyen test= y luego asigna cada resultado a la subcadena después de test= .

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!