Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!