Object.hasOwn()
Object.hasOwn() is a method that checks if an object has a specific property directly on itself, returning true if found, else false.
Syntax:
Object.hasOwn(obj, prop)
Example: This example uses the hasOwn() method to check if a property exists or not.
Javascript
let details = { name: "Raj" , course: "DSA" , website: "w3wiki.org" , } console.log(Object.hasOwn(details, 'name' )); console.log(Object.hasOwn(details, 'course' )); console.log(Object.hasOwn(details, 'phone number' )); |
Output
true true false
Supported browser:
- Chrome 1
- Edge 12
- Firefox 1
- Safari 1
- Opera 3
ECMAScript 2021 (JS 2021/2022)
JavaScript in 2021/2022 continues to evolve, with ES2021/ES2022 bringing enhanced features like private class fields, promise improvements, and record data structures, boosting developer productivity and code quality.
Contact Us