-2

I have a object as follow:

this.student = {};
this.student.id = '';
this.student.name = '';
this.student.class = '';
this.student.percentage = '';

How do i check if my student object is empty or not?

2
  • 4
    What exactly do you mean by empty? Commented Jun 12, 2018 at 8:08
  • Stack Overflow is a very active place. When you post a question (or answer), please stick around for a few minutes so you can clarify things, such as Nikhil's question above. Everyone seems to have interpreted your question as being about a truly empty object (no properties), but looking at your question, I suspect that's not correct... Commented Jun 12, 2018 at 8:20

1 Answer 1

0

To Check bject for empty try this

Object.keys(this.student).length === 0
Sign up to request clarification or add additional context in comments.

3 Comments

An object can have non-enumerable properties.
I am getting following error :TypeError: Object.keys called on non-object
@MeenakshiRathod - You will not get that error from the code above if it's used after the code in your question. Why not answer the question you were asked half an hour ago?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.