
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
From a list of IDs with empty and non-empty values, retrieve specific ID records in JavaScript
Let’s say the following is our list −
var details=[ {id:101,name:"John",age:21}, {id:111,name:"David",age:24}, {id:1,name:"Mike",age:22}, {id:"",name:"Sam",age:20}, {id: 1,name:"Carol",age:23}, {id:null,name:"Robert",age:25}, {id:1,name:"Adam",age:24}, {id:"",name:"Chris",age:23} ];
You can use the concept of filter to retrieve values based on specific ID.
Example
var details=[ {id:101,name:"John",age:21}, {id:111,name:"David",age:24}, {id:1,name:"Mike",age:22}, {id:"",name:"Sam",age:20}, {id: 1,name:"Carol",age:23}, {id:null,name:"Robert",age:25}, {id:1,name:"Adam",age:24}, {id:"",name:"Chris",age:23} ]; var getIdWithValue1 = details.filter(obj => obj.id === 1); console.log(getIdWithValue1);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo181.js.
Output
This will produce the following output −
PS C:\Users\Amit\javascript-code> node demo181.js [ { id: 1, name: 'Mike', age: 22 }, { id: 1, name: 'Carol', age: 23 }, { id: 1, name: 'Adam', age: 24 } ]
- Related Articles
- 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?
- Looping in JavaScript to count non-null and non-empty values
- Replace the empty values from a MySQL table with a specific value
- Need help selecting non-empty column values from MySQL?
- How to filter empty string values from a Java List?
- First Non-Empty String in list in Python
- How to remove an empty string from a list of empty strings in C#?
- Golang program to delete empty and non-empty directory
- Get a list of non-empty tables in a particular MySQL database?
- List of non-empty tables in all your MySQL databases?
- Query non-empty values of a row first in ascending order and then display NULL values
- GROUP BY and display only non-empty column values in MySQL
- Python | Remove empty tuples from a list
- Retrieve user id from array of object - JavaScript
- How to create Empty Values String in JavaScript?

Advertisements