Konversi String ke Object JavaScript
var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
var myobj = JSON.parse(mystr);
Anxious Alligator
var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
var myobj = JSON.parse(mystr);
const json = '{ "fruit": "pineapple", "fingers": 10 }';
const obj = JSON.parse(json);
console.log(obj.fruit, obj.fingers);
var mystr = '{ "hello":"world" }' // NB: Has enclosing ""
var myobj = JSON.parse(mystr);
console.log(myobj);
result:
{
hello: "world"
}
str = "firstName:name1, lastName:last1"; // NB: No enclosing ""
obj = eval('({' + str + '})');