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

67
Views
how to get data from arrays nested in object

I have an array with objects and I need to sum the prices from all these objects.

[{"name":"product1","value":3,"price":60},{"name":"product2","value":3,"price":12},{"name":"product3","value":3,"price":24},{"name":"product4","value":1,"price":16}]

I've tried map to get the prices only form the Array, but it doesn't work..

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

0

Well, you are gonna need a variable first. Then you iterate through all objects inside the array, adding the price to the variable.

var price = 0;

[
  { name: 'product1', value: 3, price: 60 },
  { name: 'product2', value: 3, price: 12 },
  { name: 'product3', value: 3, price: 24 },
  { name: 'product4', value: 1, price: 16 },
].forEach((val) => {
  price += val.price;
});

console.log(price);

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!