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

208
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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