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

148
Views
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 answers
Answer question

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 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!