I need to transform the contents of a txt file into a specific format:
1||fun||ball
2||job||hammer
3||run||feet
The desired output format is:
<dt>1</dt><dd>fun <img src="ball.png"></dd>
<dt>2</dt><dd>job <img src="hamm.png"></dd>
<dt>3</dt><dd>run <img src="feet.png"></dd>
I attempted the following code:
const openrooms = `1||fun||ball
2||job||hamm
3||run||feet`;
const roomlist = openrooms.split('\n');
for (var rooms in roomlist) {
room = roomlist[rooms].split('||');
for (var {roomid, name, icon} in room) {
result = `<dt>${room[roomid]}</dt><dd>${room[name]} <img src="${room[icon]}"></dd>`;
}
}
document.getElementById("destination").innerHTML = result;
<div id="destination"></div>
However, I only receive "undefined" as the result. Can someone please help me identify the issue? Feel free to test it using the fiddle link below: