- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
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
- Related Articles
- How to check for 'undefined' or 'null' in a JavaScript array and display only non-null values?
- How to check for null, undefined, or blank variables in JavaScript?
- Check for NULL or NOT NULL values in a column in MySQL
- How to get the first non-null/undefined argument in JavaScript?
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Is there is a standard function to check for null, undefined, or blank variables in JavaScript?
- Replace a value if null or undefined in JavaScript?
- How do I check for null values in JavaScript?
- Looping in JavaScript to count non-null and non-empty values
- Display first non-null values with coalesce() in MySQL?
- Return only the non-empty and non-null values from a table and fill the empty and NULL values with the corresponding column values in MySQL?
- MySQL query to display only the empty and NULL values together?
- Filtering out only null values in JavaScript
- How does COALESCE order results with NULL and NON-NULL values?
- Display 1 for NULL values in MySQL
- Ignore NULL and UNDEFINED values while running a MongoDB query

Advertisements