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

135
Vistas
How to get array of objects based on object and array list in javascript

I have an array of object, a object, and an arraylist.

I have to get the array of objects based on conditions using javascript:

  1. Fetch the array of objects if the value property matches with object item

  2. Check if the code value exists in the arraylist arraylist, if exists return array ibject

  3. Else return empty

var arrobj1 =[
  {id:1, name: zen, code: "SP", value: 100},
  {id:2, name: abi, code: "IN", value: 200},
  {id:3, name: lisa, code: "SG", value: 200}
]
var arraylist =["IN"]
var obj1={
  id:34, code: "SP", country: "mexico", item: 200
}

Expected Output:

// value & item matches, code does not exists so empty []

var arrobj2 =[
  {id:1, name: zen, code: "SP", value: 300},
  {id:2, name: abi, code: "SP", value: 200},
  {id:3, name: lisa, code: "SG", value: 100}
]
var arraylist =["IN"]
var obj2={
  id:34, code: "SP", country: "italy", item: 100
}

Expected Output

// value & item matches, code matches

[
    {id:3, name: lisa, code: "SG", value: 100}
]

I have tried using below code:

var result = arrobj1.some(e => {
        if (e.value === obj.item &&
          (arraylist.includes(e.code)){
            return true;
        }
        return false;
      });
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

First filter items, then use some.

let filtered = arrobj1.filter(({value}) => value == obj1.item)
let result = filtered.some(({code}) => arraylist.includes(code)) ? [] : filtered
about 4 years ago · Santiago Trujillo 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