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

130
Views
How to findIndex with 2 condition?

I have 2 arrays.

    Size = ['Size 0', 'Size 2', 'Size 3']

    Cart = ['1', '2', '3'] // 1, 2, 3 = product id

How to get array position with condition size = 'Size 0' and Cart = '2'?

I tried

let id = req.params.id; // id = product_id
let size = req.body.size; 
k = req.session.size.findIndex(function(a){
            req.session.cart.findIndex(function(c){ 
                return a == size && c == id;
    })
});

but it's not working

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

0

You have two separate arrays, so you will need to compute two separate indices - one for Size and one for Cart.

let productId = req.params.id;
let size = req.body.size;

const sizeIndex = req.session.size.findIndex(function(testSize){
    return testSize === size;
}); // sizeIndex is valid index as long as it isn't -1

const idIndex = req.session.cart.findIndex(function(testId){
    return testId === productId;
}); // idIndex is valid index as long as it isn't -1
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!