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

72
Views
JavaScript select a portion of variables from object

here is by JS code:

var a = { depth: object_with_many_attributes.depth };

notice how depth appear twice, any standard way to rewrite by using depth just once?

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

0

You can use Object Destructuring, but in that case, you need to define additional variables, like in an example

const object_with_many_attributes = { depth: 'xxx', 'somethingOther': 'qwerty'};

const { depth, somethingOther } = object_with_many_attributes;

const a = { depth, somethingOther };
about 4 years ago · Juan Pablo Isaza Report

0

If depth must be used only once, you can destructure it with key:

// assignment
var object_with_many_attributes = { depth: 'foo', bar: 123 };

// destructure it:
var { 'depth' : a } = object_with_many_attributes;

console.log('object a:', { a }); // use as object later

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!