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

149
Visualizações
Give every property of object value from array

I have an object and array, every element in array corresponds to object property.

It looks line this:

let keys = {
  kShift: null,
  kSpace: null,
  kEnter: null,
  kA: null,
  kS: null,
  kD: null,
  kW: null
}

let array = document.querySelectorAll('.k')
<div class="k">shift</div>
<div class="k">space</div>
<div class="k">enter</div>
<div class="k">a</div>
<div class="k">s</div>
<div class="k">d</div>
<div class="k">w</div>

I need every property of object to get corresponding value from array.

it looks so:

  keys.kShift = array[0] // first property of object is the first element in array
  keys.kSpace = array[1] // second property of object is the second element in array
  keys.kEnter = array[2] // third property of object is the third element in array

and so on

So i need to find the best way to do it

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

0

Using ES6 destructuring for array. Have to make sure the array items on right are in same order as the declared variables.

const [ kShift, kSpace, kEnter, kA, kS, kD, kW ] = document.querySelectorAll('.k')
const keys = { kShift, kSpace, kEnter, kA, kS, kD, kW }
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