
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check for Undefined or Null in a JavaScript Array
Let’s say the following is our array with non-null, null and undefined values −
var firstName=["John",null,"Mike","David","Bob",undefined];
You can check for undefined or null cases by using the following code −
Example
var firstName=["John",null,"Mike","David","Bob",undefined]; for(var index=0;index<firstName.length;index++){ if(firstName[index]!=undefined) console.log(firstName[index]); }
To run the above program, you need to use the following command −
node fileName.js.
Here my file name is demo203.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo203.js John Mike David Bob
Advertisements