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

269
Visualizações
JavaScript - Check if value is already included in an array with sub-values

I have an array that has sub-values for each value of the array and I am trying to check if a sub-value already exists within the array. Normally I would just use array.includes() but that isn't working in this case. How would I check for sub-values? Here's what I mean:

The array structure: enter image description here

What I tried:

if (dataArray.includes(`classCRN: ${classesArray[i]}`) === false) {
  // ...rest of code...
}
about 4 years ago · Santiago Gelvez
2 Respostas
Responde à pergunta

0

You can use the array.some() method to check it there are the same sub-values.

if(dataArray.some(item => item.classCRN == classesArray[i])){
......
}
about 4 years ago · Santiago Gelvez Relatório

0

Just loop through array to find property:

let arr = [
    {name: 'test', origin: 'something', value: 'bb123'},
    {country: 'Serbia', city: 'Belgrade'},
    {something: 'here', hey: 'there'}
]
console.log(isInnArray(arr,'there')) //true
console.log(isInnArray(arr,'mystring')) //false

function isInnArray(arr, findMe) {
    for(let i = 0; i < arr.length; i++) {
        for (const [key, value] of Object.entries(arr[i])) {
            if(value===findMe)
                return true
        }
    }
    return false;
}

about 4 years ago · Santiago Gelvez 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