JSON सरणी को पुनरावृत्त करने के लिए, JSON.parse() का उपयोग करें।
उदाहरण
निम्नलिखित कोड है -
var apiValues =
[
'{"name": "John", "scores": [78, 89]}',
'{"name": "David", "scores": [58, 98]}',
'{"name": "Bob", "scores": [56, 79]}',
'{"name": "Mike", "scores": [94, 91]}'
];
var parseJSONObject = apiValues.map(obj => JSON.parse(obj));
console.log("The original String : ", apiValues);
console.log("The JSON Objects : ", parseJSONObject); उपरोक्त प्रोग्राम को चलाने के लिए, आपको निम्न कमांड का उपयोग करने की आवश्यकता है -
node fileName.js.
यहाँ, मेरी फ़ाइल का नाम है demo252.js.
आउटपुट
यह कंसोल पर निम्न आउटपुट उत्पन्न करेगा -
PS C:\Users\Amit\javascript-code> node demo252.js
The original String : [
'{"name": "John", "scores": [78, 89]}',
'{"name": "David", "scores": [58, 98]}',
'{"name": "Bob", "scores": [56, 79]}',
'{"name": "Mike", "scores": [94, 91]}'
]
The JSON Objects : [
{ name: 'John', scores: [ 78, 89 ] },
{ name: 'David', scores: [ 58, 98 ] },
{ name: 'Bob', scores: [ 56, 79 ] },
{ name: 'Mike', scores: [ 94, 91 ] }
]