hasOwnProperty
returns a boolean value indicating whether the object on which you are calling it has a property with the name of the argument. For example:
var x = { y: 10 }; console.log(x.hasOwnProperty("y")); //true console.log(x.hasOwnProperty("z")); //false
However, it does not look at the prototype chain of the object.
It’s useful to use it when you enumerate the properties of an object with the for...in
construct.
If you want to see the full details, the ES5 specification is, as always, a good place to look.
Related Posts:
- What is the JavaScript equivalent of var_dump or print_r in PHP?
- What’s the difference between “{}” and “[]” while declaring a JavaScript array?
- How can I access and process nested objects, arrays or JSON?
- What does [object Object] mean?
- Array of JSON Objects
- How to iterate over a JavaScript object?
- What is the most efficient way to deep clone an object in JavaScript?
- Remove properties from objects (JavaScript)
- JavaScript: filter() for Objects
- Why is “forEach not a function” for this object?
- What is the difference between ( for… in ) and ( for… of ) statements?
- Most efficient way to convert an HTMLCollection to an Array
- What is the most efficient way to deep clone an object in JavaScript?
- What is the most efficient way to deep clone an object in JavaScript?
- Nested objects in javascript, best practices
- Sorting arrays in javascript by object key value
- Convert Array to Object
- How to display image with JavaScript?
- push object into array
- Converting an object to a string
- How do I check if an object has a key in JavaScript?
- How to add an object to an array
- How to remove all duplicates from an array of objects?
- Is there a “not in” operator in JavaScript for checking object properties?
- Sort array of objects by single key with date value
- Most efficient method to groupby on an array of objects
- Sorting object property by values
- element.setAttribute is not a function
- Complex JSON nesting of objects and arrays
- How to destroy a JavaScript object?
- Create an empty object in JavaScript with {} or new Object()?
- Checking if a key exists in a JavaScript object?
- Add JavaScript object to JavaScript object
- How to iterate (keys, values) in JavaScript?
- How do you use the ? : (conditional) operator in JavaScript?
- Error: Can’t set headers after they are sent to the client
- Automatically pausing html5 video as the ‘next’ button is pressed (javascript/ jquery)
- Express error – TypeError: Router.use() requires middleware function but got a Object
- React this.setState is not a function
- AngularJS- Login and Authentication in each route and controller
- Check if a variable is a string in JavaScript
- How to remove spaces from a string using JavaScript?
- What does !1 and !0 mean in Javascript?
- How to wait for a JavaScript Promise to resolve before resuming function?
- How to make a simple image upload using Javascript/HTML
- Check if object exists in JavaScript
- React’s setState method with prevState argument
- Can’t perform a React state update on an unmounted component
- How to simulate a click with JavaScript?
- “google is not defined” when using Google Maps V3 in Firefox remotely
- Javascript – ERR_CONTENT_LENGTH_MISMATCH
- how to call a onclick function in tag?
- Map vs Object in JavaScript
- typescript – cloning object
- Register and enqueue conditional (browser-specific) javascript files?
- Comment Reply javascript
- Refresh wp.media after ajax call
- How to preserve PHP modifications while upgrading WordPress?
- Apply jquery script to only woocommerce product pages and categories
- Saving Metadata from the Gutenberg Editor Sidebar to the Database
- How to block specific keywords from searching on WordPress?
- jQuery Hoverintent plugin in TwentyEleven Menu [closed]
- Backend option to include a javascript file on specific pages?
- White text on white background in TinyMCE when wp_editor is called in WP 3.9
- Why is this gutenberg custom format button only available from the toolbar as a dropdown?
- Script won’t execute in the media manager
- How to link external JavaScript files?
- Deregistering a script in WordPress seems impossible
- JQuery not working in my plugin [closed]
- Where to call wp_enqueue_script in a plugin with custom template?
- JavaScript Change focus to password field login page being reset
- How to select the contents in the text view textrea in wp_editor?
- How to load wp_editor via AJAX
- wordpress wp_enqueue_script() not working
- Redirect to another page using contact form 7? [closed]
- How do I add some javascript validation to the admin interface form’s onsubmit?
- I have an old version of jQuery showing up. How do I figure out where it is coming from?
- Search input area autogrow – how?
- Building a Featured Gallery component for Gutenberg
- How use wp media upload liberary in react components?
- Retrieving data about comments and likes
- Upload a web module (html and JS) to wordpress
- Need help with customalert that it would read on a normal page, but not in WordPress
- Linking Javascript in functions.php file
- Screen Options JavaScript Code
- Linking wp_enqueue can’t find the javascript file (adds “?ver=x.x.x” to the src)
- Trigger function on Remove block or add new block in Gutenberg JavaScript
- Event listener callback returns undefined element
- How to add JS script in specific pages in WordPress?
- Javascript working on jsfiddle but not wordpress site?
- How to safely pass post_id and user_id via AJAX to the backend (prevent user from changing it via JS)?
- How can i iterate through this shortcode array?
- jQuery not working for media uploader
- Put dynamic Javascript in header after doing operations
- Uncaught TypeError: undefined is not a function (shortcode-box)
- Theme customizer live preview JS- Trying to bind to an html image url without luck
- wp_deregister_script was called incorrectly
- How can create a custom plugin to call my webapi after any registration or membership plugin functionality
- hiddenQuestions.find is not a function
- How can I look at/edit what’s being sent to post.php when I hit the publish/update button?