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

174
Vistas
How to get new array of objects based on array object and array in javascript

For the array object and arrays,

return the array of objects only when

  • same value and dont have any model that matches arrayitem

  • same value and has same model whether matches or not in arrayitem

return [] when

  • same value and has atleast one model exists in the arrayitem
var arrayitem =["car", "bike"];

var arrobj1=[
  {id:1, name: "xys", model:"car", value: 200},
  {id:2, name: "abc", model:"bike", value: 200},
  {id:3, name: "tex", model:"plane", value: 300},
]
Expected Output:
// value same and model exists in arrays
[]
*****
var arrobj2=[
  {id:1, name: "xys", model:"car", value: 200},
  {id:2, name: "abc", model:"plane", value: 300},
  {id:3, name: "tes", model:"plane", value: 300},
]

Expected Output:
// both value and model same
[
  {id:2, name: "abc", model:"plane", value: 300},
  {id:3, name: "tes", model:"plane", value: 300}
]
***

var arrobj3=[
  {id:1, name: "xys", model:"car", value: 200},
  {id:2, name: "abc", model:"bike", value: 300},
  {id:3, name: "tes", model:"plane", value: 300},
]
Expected Output
//same value and alteast one matches the arrays
[]
Tried

const resultarray = arrobj1
      .map((obj, i) => {
        return arrobj1.find((element, index) => {
          if (i !== index && element.value === obj.value) {
            if(element.model !== obj.model && 
              (!arrayitem.includes(element.model) && !arrayitem.includes(obj.model))){
              return obj;
            } if(element.model === obj.model) {
              return obj;
            }
          }
        })
      })
      .filter(x => x);
    return resultarray;

about 4 years ago · Juan Pablo Isaza
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