JSON Extract Data

You are Here:

JSON Extract Data

The JavaScript offers two ways in which one can assign or retrieve a value from an instance. They are

  • Dot notation
  • Bracket notation

Dot Notation

In the following example, we use dot notation to access the name (key) of the first object in the data variable.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Extract Data</h1> <p id="point"></p> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36 }, { "name": "Alex", "age": 30 } ] function myFunction(){ document.getElementById("point").innerHTML = data[0].name; } </script> </body> </html>

Bracket Notation

In the following example, we use bracket notation to access the name (key) of the first object in the data variable.

Example

HTML Editor
<!DOCTYPE html> <html lang="en-US"> <body> <h1>JSON Extract Data</h1> <p id="point"></p> <button onclick="myFunction()">Click Me</button> <script> var data = [ { "name": "Mike", "age": 36 }, { "name": "Alex", "age": 30 } ]function myFunction(){ document.getElementById("point").innerHTML = data[0]["name"]; } </script> </body> </html>

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