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

246
Views
Is this how you would define multiple constants using index?

So just a quick questions since I'm relatively new to javascript.

Let's say I have

const {a, b, c, d} = items[i]

and I have a list of items somewhere in the document. What would this code render? What does it essentially stand for? I know how to define multiple constants in one line but I get confused when you incorporate the index (i). Any explanation would help. Thank a ton!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

{a, b, c, d} means you are destructuring the properties of an object. In this case you are destructuring to define the const variables a,b,c,d.

items is built with multiple objects. So we destructure the items[2] object properties to define the const variables.

const items = [
{a: 0, b: 0, c: 0, d:0},
{a: 1, b: 1, c: 1, d:1},
{a: 2, b: 2, c: 2, d:2}
] 

const {a, b, c, d} = items[2]

console.log(a) // <--- outputs 2

You can also destructure the array by doing something like so:

const items = [
{a: 0, b: 0, c: 0, d:0},
{a: 1, b: 1, c: 1, d:1},
{a: 2, b: 2, c: 2, d:2}
] 

const [obj1, obj2, obj3] = items

console.log(obj1) // <--- outputs {a: 0, b: 0, c: 0, d:0}

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!