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

133
Views
Filtrar usando datos que están en una matriz dentro de otra matriz
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}] }]

Quiero filtrar productos usando el valor de tamaño que está dentro de la matriz sizeStock que está dentro de la matriz de productos.

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

Por ejemplo intento esto para filtrar todos los productos que tienen la talla 40. Pero no funciona.

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

0

Puede lograr fácilmente este resultado usando el filtro y algunos como

 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!