Categories
JavaScript Answers

How to Get a JSON Object’s Key and Value in JavaScript?

Spread the love

To get a JSON object’s key and value in JavaScript, we can use the JSON.parse method to parse the JSON object string into a JavaScript object.

Then we can get a property’s value as we do with any other JavaScript object.

For instance, we can write:

const data = `{
  "name": "",
  "skills": "",
  "jobtitel": "Entwickler",
  "res_linkedin": "webSearch"
}`

const parsedData = JSON.parse(data);
console.log(parsedData.name);
console.log(parsedData.skills);
console.log(parsedData.jobtitel);
console.log(parsedData.res_linkedin);

We have the data JSON string that we parse into an object with JSON.parse and assigned it to parsedData .

Then we can get the properties from parsedData with the dot notation as we do with any other JavaScript object.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *