I have this JS object that is stored in a file called garage.js:
var myObject = {
"cars": [
{
"type": "mustang",
"body": {
"length": 10.7,
"width": 5.8,
"color" : "#fff"
}
},
{
"type": "corvette",
"body": {
"length": 11.9,
"width": 5.6,
"color": "#000"
}
}]
};
When I make changes to the width wtihin a JS function within html, like this:
myObject.cars[0].body.width = 6
and then check the variable to see if the value has been updated, like this:
console.log(myObject.cars[0].body.width = 6)
the console prints 6... but it does not change the value in the stored object in garage.js... (how do I do this?)
The value appears to be represented locally but I need it to actually write this updated value back to the garage.js file so that it is stored permanently, so that when I refresh the html in the browser, the new value, 6, will have replaced the old value, 5.8, in the myObject object.
Do I need to use JSON.stringify and JSON.parse? ... or is it much simpler than that?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire