Sometimes, we want to get a JSON object’s key and value in JavaScript.
In this article, we’ll look at how to get a JSON object’s key and value in JavaScript.
Get a JSON Object’s Key and Value in JavaScript
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.
Conclusion
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.