- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- 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
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.
Advertisements