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

135
Views
Filter using data that is in an array inside another array
const products = [
{
    "id": 1,
    "category": "footwear",
    "gender": "man",
    "brand": "Topper",
    "model": "classic",
    "color": "black",
    "price": 1800,
    "sizeStock": [{"size": 34, "stock": 0}, {"size": 35, "stock": 3}, {"size": 36, "stock": 5}]
},
{
    "id": 2,
    "category": "footwear",
    "gender": "man",
    "brand": "Topper",
    "model": "rainbow",
    "color": "multi",
    "price": 3500,
    "sizeStock": [{"size": 139, "stock": 1},{"size": 40, "stock": 5},{"size":41, "stock":1}]
}]

I want to filter products using the size value that is inside of sizeStock array that is inside of products array.

products.forEach((product) => {
    product.sizeStock.filter((a) => a.size === 40);
});

For example I try this to filter all the products that have the size 40. But it´s not working.

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

0

You can easily achieve this result using filter and some as

products.filter((p) => p.sizeStock.some((o) => o.size === 40))

const products = [
  {
    id: 1,
    category: "footwear",
    gender: "man",
    brand: "Topper",
    model: "classic",
    color: "black",
    price: 1800,
    sizeStock: [
      { size: 34, stock: 0 },
      { size: 35, stock: 3 },
      { size: 36, stock: 5 },
    ],
  },
  {
    id: 2,
    category: "footwear",
    gender: "man",
    brand: "Topper",
    model: "rainbow",
    color: "multi",
    price: 3500,
    sizeStock: [
      { size: 139, stock: 1 },
      { size: 40, stock: 5 },
      { size: 41, stock: 1 },
    ],
  },
];

const result = products.filter((p) => p.sizeStock.some((o) => o.size === 40));
console.log(result);

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!