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

148
Views
trying to grab a value from an array in javascript

im trying to make it so it only shows specific sizes for the array i have, this is the array

const products = [{
    name: "14K bracelet",
    id: "1",
    description: "Beautfull 14K gold Bracelet",
    price: 100,
    size: [1, 2, 3, 4]
    
}

and this is how im trying to grab the values from it

                    <Dropdown.Item className="dropdown-item" href="#/action-1">{products.size[0]}</Dropdown.Item>

but im getting this error

TypeError: Cannot read properties of undefined (reading '0')
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Do it like this:

const products = {
    name: "14K bracelet",
    id: "1",
    description: "Beautfull 14K gold Bracelet",
    price: 100,
    size: [1, 2, 3, 4]    
}
about 4 years ago · Juan Pablo Isaza Report

0

you are trying to get access to to an object in array so it should be like

let product = [{name:'test', size:[1,2,3,4]}]

console.log(product[0].size[1])

about 4 years ago · Juan Pablo Isaza Report

0

You should use 'products' as an array instead of object.

Arrays have elements(object - keys). For working with them you must use indexes(f.e. array[0] for getting the first element).

For more information:

Arrays: https://www.w3schools.com/js/js_arrays.asp

Objects: https://www.w3schools.com/js/js_objects.asp

const products = [{
    name: "14K bracelet",
    id: "1",
    description: "Beautfull 14K gold Bracelet",
    price: 100,
    size: [1, 2, 3, 4]
    
}];

console.log(products[0].size[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!