Is there a way to use the for...in loop to iterate over the properties of two objects simultaneously? Assume for the sake of the argument that I need them to appear back to back in the console log (ie first property of element1 followed by first property of element2, the second property of element1, the second property of element2, and so on.....). This is a toy example that has no immediate practical application. I just want to understand the concept. If there is not a way to do this with the for...in loop is there a way to achieve the same effect assuming that I don't know anything about the number of properties that element1 and element2 have? The following code obviously will not work but captures the spirit of my intent (I hope...)
function test(element1, element2) {
for(var x in element1) {
console.log(element1[x]);
console.log(element2[x]);
}
return true;
}
element1 = {0:0, 1:1, 2:2};
element2 = {a:0, b:1, c:2};
test(element1, element2);