Skip to content

JavaScript print object properties | Example code

  • by

Use JavaScript the Object.keys() function to get an array of the properties of the object and print. To print, you can use console.log or innerHTML.

Example print object properties in JavaScript

Simple example code prints all the properties of the object.

In this example, we pass the person object to Object.keys() as an argument. This method returns an array that can be further iterated using the forEach() method as shown below.

<!DOCTYPE html>

   const person = {
    name: 'John Bond',
    age: 35,
    secretIdentity: 'Jane wicks',
    powers: ['Punch', 'Damage resistance', 'Laser']

  Object.keys(person).forEach((prop)=> console.log(prop));



JavaScript print object properties

to print with values

console.log(JSON.stringify(object, null, 4));

Do comment if you have any doubts or suggestions on this JS Print object code.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *