JS

HOW TO CHECK IF PROPERTY EXISTS IN OBJECT

THE OBJECT

var obj = {  Name: "Jon", Email: "jon@doe.com", Gender: "Male" };

1) HAS PROPERTY

var exist = obj.hasOwnProperty("Name");

var keys = Object.keys(obj); var exist = keys.includes("Email");

2) EXTRACT KEYS

var exist = "Email" in obj;

3) IN OPERATOR

var exist = obj["Email"] !== undefined;

4) COMPARISON

var check = "Email", exist = false; for (let key in theObject) {    if (key == check) {     exist = true; break;   } }

5) MANUAL LOOP