Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda