
- 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
Set JavaScript object values to null?
In order to set object values to null, you need to get all the keys from the object and need to set null. You can use for loop or forEach() loop.
Following is the JavaScript code with name records. We will set the object value to null −
const object=[ { FirstName:"John" }, { FirstName:"David" }, { FirstName:"Bob" } ] Object.keys(object).forEach(key => object[key]=null); console.log(object);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo31.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo31.js [ null, null, null ]
Above, all the values are now set to NULL.
- Related Articles
- How to set JavaScript object values dynamically?
- Filter away object in array with null values JavaScript
- MySQL query to set values for NULL occurrence
- How to set default values when destructuring an object in JavaScript?
- JavaScript/ Typescript object null check?
- How to automate this object using JavaScript to set one key on each iteration as null?
- Convert set to object - JavaScript?
- Filtering out only null values in JavaScript
- How to avoid inserting NULL values to a table with JavaScript?
- Populate null columns in a MySQL table and set values
- Set value only for NULL values in a MySQL table
- How to set NULL values in a table column and insert the same
- Looping in JavaScript to count non-null and non-empty values
- Set a custom value for NULL or empty values in MySQL
- How do I check for null values in JavaScript?

Advertisements