user8317064
user8317064

Reputation:

How to display all properties of an object in Angular JS?

I have an object, say object obj. Obj has several properties(int id, boolean status, etc) and I know I want to access some of the properties. Yet because I do not know where I defined this object, I would like to know the best way to display all the properties of the object using console.log.

Hey all, when I tried using console.log(obj); it did not work. That is the reason I posted this question. For some reason, in my application; it returned obj obj instead of the properties or letting me open up the properties. I haven't tried the console.log(JSON.stringify(obj)); but the command console.log(Object.getOwnPropertyNames(intended_obj));worked exactly as intended.

Upvotes: 1

Views: 3364

Answers (3)

GiorgosPap
GiorgosPap

Reputation: 31

You could also use console.table(obj). According to MDN:

// an object whose properties are strings
function Person(firstName, lastName){
  this.firstName = firstName;
  this.lastName = lastName;
}

var me = new Person("John", "Smith");
console.table(me);

Browser's console: image

Upvotes: 1

Amit Shahani
Amit Shahani

Reputation: 94

use console.log(JSON.stringify(obj)) to display the proper json string of the object.

Upvotes: 0

user8317064
user8317064

Reputation:

So the correct answer is using console.log(Object.getOwnPropertyNames(intended_obj)); This will list all the properties of the object in an array!

Upvotes: 0

Related Questions