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

71
Views
Ignoring a key while destructing in JavaScript

We can ignore a value while destructing a list:

[a,,...rest] = [1,2,3,4] //2 is ignored here
console.log(a); // 1
console.log(rest); // [3,4]

Can we do something similar for dictionaries? I tried, but it gives error:

({ a, , c} = { a: 10, b: 20, c: 30 }); //Unexpected token ',
/* I was expecting a to get assigned 10 and c to get assigned 30 */

Is it simply impossible to do the same with dictionaries? If yes, then why such a language design decision? Or it's just the parser incapability?

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

0

Here is how to do it:

({a,c} = { a: 10, b: 20, c: 30 }) 

console.log(a)
console.log(c)

The first one works that way because it's a spread in then end.
The second one sees it as a trailing comma.

about 4 years ago · Juan Pablo Isaza Report

0

You can just do that.

({ a, c} = { a: 10, b: 20, c: 30 }); 
console.log(a);
console.log(c);

about 4 years ago · Juan Pablo Isaza Report

0

Yes you can ignore the key while destructing the dictionaries/object like below :-

( { a, ...remObj} = { a: 10, b: 20, c: 30 }); 
console.log(a, '   ',remObj);

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!