I have the following source:
var testext = {
"key1": "String1/1",
"key2": "String2/1",
"key4": "String4/1",
};
for (i = 0; i < testext.length; i++) {
if (testext["key" + i]) {
var outouter = "key: " + testext["key" + i];
document.getElementById("id" + i).innerHTML = outouter;
}
}
<p>Testpage with array values</p>
<div id="id1">Nothing set 1</div>
<div id="id2">Nothing set 2</div>
<div id="id3">Nothing set 3</div>
<div id="id4">Nothing set 4</div>
<div id="id5">Nothing set 5</div>
The way this is supposed to work is that the loop takes all the keys in the table and checks if there is a value to them and than writes that value to the div the value is there for.
If possible it would be great to have a key div mapping like key1 -> sorter, key2 -> boarder, key3 -> cars and so on, but this is far over my reach so I stick to the counting version.
The output should be:
String1/1 String2/1 Nothing set 3 String4/1 Nothing set 5
But for some reason this is not working. Any ideas of what is wrong?