I'm experiencing an issue with getting the value from a javascript array.
var color = new Array();
for (var i = 0; i < datafeatures.length - 1; i++) {
color[datafeatures[i].properties.userid] = datafeatures[i].properties.linecolor;
}
snapshot.forEach(function (childSnapshot) {
var colour = childSnapshot.wp_user;
console.log(color[colour]);
console.log(JSON.stringify(color));
console.log(color);
console.log(colour);
}
Console.log result:
color[colour]: undefined
JSON.stringify(color): []
color:
[]
26: "#9d36ee"
45: "#b1c743"
56: "#f9c53c"
61: "#d770ce"
63: "#267fa1"
64: "#85002f"
68: "#78eca8"
92: "#a4a2e7"
length: 93
__proto__: Array(0)
colour: 61
Expected output from color[colour]: "#d770ce"
Real output from color[colour]: undefined.
Color has something in it, Colour is a number (key), but it seems impossible to get a value from Color..
snapshot, is that the correct variable ?coloursand one of its elementscolour. Naming the arraycolorand one of its elementcolouris just confusing.console.log(JSON.strinify(color));returns[]and as you pointed out in your answer below, when changing the color array to an object, it returns{}console.log(color)