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

214
Vistas
Javascript : Check if any of the element in array is null or empty (Return True-False)

I have below array in javascript -

[
{
 id:1,
 deptName:"Cashier"
},
{
 id:2,
 deptName:"MF"
},
{
 id:3,
 deptName:""
},
{
 id:4,
 deptName:"RD"
},
{
 id:5,
 deptName:null
},
]

I want to check if any element for deptName in above array is null or empty.

I used -

var isNullOrEmpty= data.every(ele=>(ele.deptName===null || ele.deptName==="")) 

use of every function is returning false in every case. i.e. whether I keep deptName in any of the element to be null / empty or I fill it with value. With both the cases it is returning me false.

I want to check if any of the deptName in array is null or empty.

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

0

every() method in JavaScript is used to checks whether all the elements of the array satisfy the given condition or not. The Array. some() method in JavaScript is used to check whether at least one of the elements of the array satisfies the given condition or not.
For your issue:

  var isNullOrEmpty= data.some(ele=>(ele.deptName===null || ele.deptName==="")) 
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also use array.map function with an if to check if the value not exist or empty:

arr.map((item, index) => {
 if (!item?.deptName) {
     console.log(`array index =>[${index}] is null or empty.`);
    }
 });
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