Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

168
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda