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

168
Vistas
How to see if values are in the same "line" within an object in javascript

Not sure how to approach this problem, but I want to see if two values are in the same 'line'

var inventory_needed = [
    { section: "hardware",          supplies: "hammers"                       },
    { section: "plumbing",          supplies: "pipes"                         },
    { section: "garden",            supplies: "grass seeds"                   },
    { section: "cleaning supplies", supplies: ["hand sanitizer", "detergent"] },
    { section: "appliances",        supplies: ["fridges", "dishwashers"]      } 
];

psuedocode of what I want to try to attempt

if(section.value && supplies.value in the same line) {
    return true;
}
else {
    return false;
}

//example 1
if("appliances" && "fridges" in the same line) {
    return true; //would return true
}
else {
    return false;
}

//example 2
if("plumbing" && "fridges" in the same line) {
    return true; 
}
else {
    return false; //would return false
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

By in the same line, you seem to mean defined within the same object in the array. If that's correct, the way to do that is like this:

function inTheSameLine(section, supplies){
    return inventory_needed.some(obj => {
        return obj.section === section && (
            obj.supplies === supplies || (
               Array.isArray(obj.supplies) && obj.supplies.includes(supplies)
            )
        );
    });
}

The JavaScript array some function returns true if any of the array elements satisfy the condition.

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