

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
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 Questions & Answers
- How to check for null, undefined, or blank variables in JavaScript?
- Check for NULL or NOT NULL values in a column in MySQL
- Display only NOT NULL values from a column with NULL and NOT NULL records in MySQL
- Replace a value if null or undefined in JavaScript?
- Is there is a standard function to check for null, undefined, or blank variables in JavaScript?
- Looping in JavaScript to count non-null and non-empty values
- How do I check for null values in JavaScript?
- How does COALESCE order results with NULL and NON-NULL values?
- 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?
- Display first non-null values with coalesce() in MySQL?
- Filtering out only null values in JavaScript
- Display 1 for NULL values in MySQL
- MySQL query to display only the empty and NULL values together?
- Ignore NULL and UNDEFINED values while running a MongoDB query
- Perform mathematical calculations in a MySQL table with NULL and NON-NULL values
Advertisements