Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

255
Visualizações
How to get next value (after , value)

I have data like this =

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

I want to get value for BP for HP and For COST so how can I get value next to , .

explaination


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 Respostas
Responde à pergunta

0

You can try to get index of that key. For example: From your array, the index of BP is 5, the index of next value (23) is 6

From that example, we can have this logic (array is your name of 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 Relatório

0

Assuming you know the keys to BP, HP and COST (and I am not misunderstanding your question) - you can just +1 the index.

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 Relatório

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)

You can have a simple loop and combine with indexOf + 1 to get the value you want, assuming the position is predictable

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda