Home >Web Front-end >JS Tutorial >How to Extract Values from a JSON String in JavaScript?
Question:
How to extract values (result and count) from a JSON string in JavaScript?
Response:
The JSON object built into JavaScript can be used to parse a JSON string:
How to Use JSON.parse() to Extract Values:
Example:
var response = '{"result":true,"count":1}' const resultObject = JSON.parse(response); console.log(`result: ${resultObject.result}, count: ${resultObject.count}`); // Output: // result: true, count: 1
Using this approach, you can easily extract key-value pairs from JSON strings and manipulate the data in your JavaScript code.
The above is the detailed content of How to Extract Values from a JSON String in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!