Check the existence of a key in JavaScript Object

How to check the existence of a key in JavaScript Object

const myObj = { a: 1, b: 2};

We need to check whether I’d exist in object or not!

const result = myObj.hasOwnProperty('id'); // false

Or

const result = 'id' in myObj; // false

Or

const result = myObj.id !== undefined; // false

Comments

Popular posts from this blog

world tourism guide Template

Es6 how to check if value is not null or undefined?