JSON hasOwnProperty() Method

You are Here:

JSON hasOwnProperty()

JSON hasOwnProperty() is a JavaScript method that returns a boolean indicating whether the object has the specified property as its own property.

In the following example, we will check whether the first object in an array (data) has age and hair properties.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON hasOwnProperty()</h1> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36, "married": true } ] function myFunction(){ console.log(data[0].hasOwnProperty("age")) console.log(data[0].hasOwnProperty("hair")) } </script> </body> </html>

Syntax

object.hasOwnProperty("key");

Reminder

Hi Developers, we almost covered 100% of JSON Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JSON.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author