I am working with a json file and two variables. I need to save the values of these variables in the json file using the push function. Here's my initial code:
var x = 'xmen';
var z = 'xmen website';
var jsonObj = {
"items":
[
{
"title": "some title",
"url": "some url"
}
]
};
The desired output in the json file should be:
var jsonObj = {
"items":
[
{
"title": "some title",
"url": "some url"
},
{
"title": "xmen",
"url": "xmen website"
}
]
};
Instead of using arrays while pushing the value using:
jsonObj.items.push
I want to call the variable and assign it directly, like this example:
jsonObj.items.push({"title": +x + ,"url": +z + }); // This is just for demonstration purposes.