I have the following 2 files, an HTML file and a JSON file called data.txt
In the JSON:
myFunction([
{
"itemid": "0",
"itemname": "air",
"currentprice": "5.0"
},
{
"itemid": "1",
"itemname": "stone",
"currentprice": "5.0"
},
{
"itemid": "2",
"itemname": "grass",
"currentprice": "5.0"
},
{
"itemid": "3",
"itemname": "dirt",
"currentprice": "5.0"
},
{
"itemid": "4",
"itemname": "cobblestone",
"currentprice": "5.0"
},
{
"itemid": "5",
"itemname": "plank",
"currentprice": "5.0"
}
]);
So basically, to my knowledge the only way to modify or view data from this file is with a loop like the following:
<div id="id01"></div>
<script>
function myFunction(arr) {
var out = "";
var i;
for(i = 0; i<arr.length; i++) {
out += '<a href="' + arr[i].url + '">' + arr[i].itmid + '</a><br>';
}
document.getElementById("id01").innerHTML = out;
}
</script>
<script src="data.js"></script>
My questions is this, is there a way to directly edit the values without a loop, possibly similar to editing arrays like itemid[number] = "customValue"