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

268
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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