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

291
Visualizações
JavaScript: Extract one number value out of key-value array and store them in a Variable

I do an InfluxDB query and get exact one result row like this:

{"result":[[{"result":"_result","table":0,"_start":"2022-01-28T09:00:12.676771291Z","_stop":"2022-01-29T09:00:12.676771291Z","_measurement":"Strom.Heizung.Energie_in_der_letzten_Stunde","_value":14.683000000000117,"_time":"2022-01-29T09:00:12.676771291Z","ts":1643446812676}]],"ts":1643446812684,"error":null}

I need the value of the _value key in a variable e.g. value. In this example the 14.683000000000117

I tried it with the map-function:

value = query.result[0].map(elm => (elm._value));

but I get the value in brackets like [14.683000000000117]

How can I get the number in my value variable?

Thanks

Frank

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

map() returns an array, even if it's an array of length 1. So, you want to retrieve the first element of the array it returns. You can achieve that by appending [0] at the end:

value = query.result[0].map(elm => (elm._value))[0];

Learn more on accessing array elements here, in the "Accessing Array Elements" section: https://www.w3schools.com/js/js_arrays.asp

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