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

212
Views
How to get a data from an object inside of a function (JS)

let's say that I have a function that includes an object

const someFunc =props=> ({
styles:{
somedata: 'somedata:',
},
infoSectionValue: {
 bold: true,
},
images:{
 donut: props.donut_base64,
icon: 'some icon'
},
 content: [1,2,3]
}
})`
now I want to get the icon using object destruction
`const {images :{ icon }} = someFunc()
console.log(icon)

ERROR : props not define it didn't work while there are other objects or props included how can I get the icon in this case?

this is only way only have worked, if the function is to maintain the object:

const someFunc =props=> {
images:{
icon: 'some icon'
}
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You probably mean object destructuring, not destruction.

This works (you're missing parenthesis):

Edit: There are multiple errors in your example code, this shows a couple of options:

 const someFunc = props => ({
    foo: 87,
    bar: { foo: 'hi' }

});

const { bar: { foo: msg } } = someFunc();

console.log(msg);

const { bar: bar } = someFunc();

console.log(bar)
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!