I'm trying to figure out the best way to do something. I have a variable that acts as a HTML template, and insert properties from an array of objects. Simple code below:
i = 0;
v = "<li>",
v += array[i].prop,
v += "</li>";
Array of objects:
array = new Array();
array[0] = { name: "1",
prop: "Property 1"
}
array[1] = { name: "2",
prop: "Property 2"
}
This is the bit thats getting me:
for (; i < array.length ;) {
i += 1;
console.log(i);
$("body").append(v);
}
i returns as 0 and 1 in the console, but the prop value returns as "Property 1" twice. As far as I'm aware, since I haven't declared i in the for loop it should be returning the new value of i to the originally declared variable. This is obviously a scope issue that I'm missing/don't understand.
Thanks in advance.
ito the originally declared variable"?iin the assignment tovbefore you are assigning anything toi. Is that what actually happens?) Do you have anyvardeclarations?vis not reassigned inside the loop, how is it expected to change?