-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?

  • 4
    What exactly do you mean by **empty**? – Nikhil Aggarwal Jun 12 '18 at 08: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... – T.J. Crowder Jun 12 '18 at 08:20

1 Answers1

0

To Check bject for empty try this

Object.keys(this.student).length === 0
  • An object can have non-enumerable properties. – T.J. Crowder Jun 12 '18 at 08:11
  • I am getting following error :TypeError: Object.keys called on non-object – Meenakshi Rathod Jun 12 '18 at 08:35
  • @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](https://stackoverflow.com/questions/50812197/how-to-check-if-my-object-is-empty-in-javascript#comment88629635_50812197)? – T.J. Crowder Jun 12 '18 at 08:42