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

115
Vistas
how to get only boolean value from a nested array

This might seems silly, but I'm trying it from long time.

var parentArray = [
  [0.49988811188811194, 0.17249417249417248],
  [0.8181398601398602, null],
  [0.8181398601398602, 0.47785547785547783],
  [0.49988811188811194, 0.47785547785547783]
];

function containsNull(arr) {
  return (function() {
    return arr.filter(e => {
      if(e.some(el => el == null)) return true
    })
  })();
}

console.log("-->", containsNull(parentArray))

here I'm getting output as

> "-->" Array [Array [0.8181398601398602, null]]

but I don't need the array as return value. I just want true or false that's all.

i.e, 

"-->" true

How to achieve this? even using load-ash library is good to go!

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You can use some with includes

var parentArray = [
  [0.49988811188811194, 0.17249417249417248],
  [0.8181398601398602, null],
  [0.8181398601398602, 0.47785547785547783],
  [0.49988811188811194, 0.47785547785547783],
];

const result = parentArray.some((a) => a.includes(null));
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar

0

It seems that you are using a multidimensional array, so you could just flatten it with Array.prototype.flat and use Array.prototype.includes to check if the flattened array contains null.

let parentArray = [
  [0.49988811188811194, 0.17249417249417248],
  [0.8181398601398602, null],
  [0.8181398601398602, 0.47785547785547783],
  [0.49988811188811194, 0.47785547785547783]
];

const containsNull = (arr) => arr.flat().includes(null)

console.log(containsNull(parentArray))

The following would flatten arrays of n-dimensions and check if it contains null:

function flatten(arr) {
  return arr.reduce(function (flat, toFlatten) {
    return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
  }, []);
}

let parentArray = [
  [[[[0.49988811188811194, 0.17249417249417248]]],
  [0.8181398601398602, null],
  [0.8181398601398602, 0.47785547785547783]],
  [0.49988811188811194, 0.47785547785547783]
];

const containsNull = (arr) => flatten(arr).includes(null)

console.log(containsNull(parentArray))

about 4 years ago · Juan Pablo Isaza Denunciar

0

Use Array.some() method on both parent and child array.

var parentArray = [
  [0.49988811188811194, 0.17249417249417248],
  [0.8181398601398602, null],
  [0.8181398601398602, 0.47785547785547783],
  [0.49988811188811194, 0.47785547785547783]
];

function containsNull(arr) {
  return arr.some(list => list.some(ele => !ele))
}

console.log(containsNull(parentArray));

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