How to check if an object has a specific property in JavaScript

1 Answer

0 votes
const user = {
    id: 928737,
    name: 'Rose'
};
 
 
console.log(user.hasOwnProperty('name')); 
console.log(user.hasOwnProperty('city')); 
 
 
/*
run:
   
true 
false

*/

 



answered Nov 8, 2019 by avibootz
edited Apr 1, 2024 by avibootz
...