I'm building on a recent question I asked: Change SVG path color using data in JavaScript function
I have an object:
var body_data = { head: 10, left-shoulder: 20, right-shoulder: 40, left-arm: 60, right-arm: 90, left-hand: 100, right-hand: 25, chest: 50, stomach: 15, left-leg: 20, right-leg: 17, left-foot: 42, right-foot: 100}
I also have an ifelse statement that assigns color based on value:
var color;
if (value < 25) {
color = "blue";
} else if (value < 50) {
color = "green";
} else {
color = "red";
}
I'd like to apply a function where I loop through each key-value pair, changing the color of the element based on its color value
document.getElementById(key);
if (element) {
element.style.fill = color;
}
How do I properly use for....in
to loop through my object, where the keys are the IDs of elements and the values the color?