उदाहरण
स्ट्रिंग टाइप वैल्यू को ऐरे टाइप में बदलने के लिए JSON.parse() मेथड का उपयोग करें।
var customerDetails = '[ { "name": "John", "countryName": "US" }, { "name": "David", "countryName": "AUS" }, { "name": "Bob", "countryName": "UK" } ]';
console.log("The actual value=" + customerDetails);
var convertStringToArray = JSON.parse(customerDetails);
console.log("After converting string to array objects=");
console.log(convertStringToArray);
प्रोग्राम चलाने के लिए:
node fileName.js
आउटपुट
PS C:\Users\Amit\JavaScript-code> node demo123.js
The actual value=[{"name": "John", "countryName": "US"}, {"name": "David", "countryName": "AUS"}, {"name": "Bob", "countryName": "UK"}]
After converting string to array objects=[ { name: 'John', countryName: 'US' }, { name: 'David', countryName: 'AUS' }, { name: 'Bob', countryName: 'UK' } ]