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

247
Views
Cómo obtener el siguiente valor (después de , valor)

Tengo datos como este =

 Hi,I,Am,Here,to,BP,23,HP,34,COST,45

Quiero obtener valor para BP para HP y para COST, entonces, ¿cómo puedo obtener valor junto a , .

explicacion

 const array = [BP,HP,COST] const string = ["HI","I","AM","BP","20","HP","35","COST","30"] expected output = Value of BP is 20, Value of HP is 35, Value of COST is 30
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Puede intentar obtener el índice de esa clave. Por ejemplo: de su matriz, el índice de BP es 5 , el índice del siguiente valor (23) es 6

A partir de ese ejemplo, podemos tener esta lógica (la array es el nombre de la variable)

 const array = ["BP","HP","COST"] const string = ["HI","I","AM","BP","20","HP","35","COST","30"] const newArray = [] for (const key of array) { newArray.push(string[string.indexOf(key) + 1]) }

about 4 years ago · Juan Pablo Isaza Report

0

Suponiendo que conoce las claves de BP, HP y COST (y no estoy malinterpretando su pregunta), puede hacer +1 en el índice.

 var data = ["Hi", "I", "Am", "Here", "to", "BP", 23, "HP", 34, "COST", 45]; var indexBP = data.indexOf("BP"); var BP = data[indexBP + 1]; // BP = 23
about 4 years ago · Juan Pablo Isaza Report

0

 const array = ['BP','HP','COST'] const string = ["HI","I","AM","BP","20","HP","35","COST","30"] let output = ""; array.forEach(x => { output += `Value of ${x} is ${string[string.indexOf(x) + 1]} ` }) console.log(output)

Puede tener un bucle simple y combinarlo con indexOf + 1 para obtener el valor que desea, suponiendo que la posición sea predecible

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!