I have an object that looks like this
var nodes = [{
'name': 'Test1',
'address': 'Street 1',
'zipcode': '1234',
'city': 'Big City',
'phone': '12345678',
'email': '[email protected]',
'web': 'www.test.com'
},
{
'name': 'Test12',
'address': 'Street 5',
'zipcode': '5678',
'city': 'Bigger City',
'phone': '89898989',
'email': '[email protected]',
'web': 'www.test2.com'
}
]
What I want is to loop through this object and dynamically create a span element with a textNode from the value, and use the key for a class
var elm = document.createElement('span')
elm.appendChild(document.createTextNode(THEVALUE))
elm.setAttribute('class', THEKEY)
li.appendChild(elm)
Currrently I am using a basic for-loop, but I am not sure about the best way to extract the key only
for (var i = 0; i < nodes.length; i++) {
var elm = document.createElement('span')
elm.appendChild(document.createTextNode(nodes[i]))
li.appendChild(elm)
}
The expected result would be
<span class="name">Test1</span>
<span class="address">Street 1</span>
I am using vanilla JS
class?<span class="name">Test</span><span class="address"...or what?