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

238
Visualizações
How to check the duplicates property in array of objects based on condition javascript

I have array of object arrayobj in which have to check property value of

code and type based on condition return statement no add or can add in javascript

in arrobj for type-local, if type local and code values not reappearing in other object return 'can add' else return 'no add'

in arrobj for type-FL or FL Travel, if different type and code values reappearing in other object return 'can add'

in arrobj for type-FL or FL Travel if type and code both reappearing in object return 'no add'

How to check above condition in javascript,

have tried code without checking property type, got stuck

function checkValues(arrob){
 const checkcode = arrob.map(elem => elem.code);
if (arrob.length !== new Set(checkcode).size) {
 return "no add";
} else {
 return "can add"
}
}
checkValues(arrobj1);
checkValues(arrobj2);
checkValues(arrobj3);

sample objects for scenario

var  arrobj1=[
  {id:1, name: "ram", code: "NIXZ", type: "Local"},
  {id:2, name: "abey", code: "ABCN", type: "FI"},
  {id:3, name: "jaz", code: "ABCN", type: "FI Travel"}
]
var  arrobj2=[
  {id:1, name: "ram", code: "NIXZ", type: "Local"},
  {id:4, name: "zain", code: "NIXZ", type: "FI"},
  {id:2, name: "abey", code: "ABCN", type: "FI"},
  {id:3, name: "jaz", code: "ABCNE", type: "FI Travel"}
]
var  arrobj3=[
  {id:1, name: "ram", code: "NIXZ", type: "Local"},
  {id:4, name: "sam", code: "ABCN", type: "FI"},
  {id:2, name: "abey", code: "ABCN", type: "FI"},
  {id:3, name: "jaz", code: "ABCNE", type: "FI Travel"}
]

Expected Result

//for arrobj1 [type-FL or FL Travel, different type and same code appears]
can add

//for arrobj2 [type local, same code appears] 
no add

//for arrobj3 [type-FL or FL Travel, same type and same code appears] 
no add

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.

const rawArray = [arrobj1 , arrobj2 , arrobj3]
const hasDups = (objArray) => {
    objArray.ForEach(el => {
        if (objArray.Includes(el.type))
            return true;
        return false;
    });    
}
const newArray = rawArray.map(el => !hasDups(el));
about 4 years ago · Juan Pablo Isaza Relatório
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