Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

150
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda