I've been looking for answers for quite some time now and none of what I've seen is right for my situation. Here is my code:
colors:
red : "255, 0, 0"
blue : "24, 149, 207"
green : "74, 165, 76"
grey : "202, 202, 202"
black : "0, 0, 0"
yellow : "183, 118, 4"
purple : "83, 74, 166"
white : "255, 255, 255"
for color, rgb, index of colors
console.log index
I know that it is not working and I've seen many post about a simple array with a loop that looks like that:
for color, index in colors
console.log index
I'm wondering if there is a way to do something like that with associative array or if I have to create define an index variable like this:
index: 0
for color, rgb of colors
console.log index
index++
for ... ofloop is just a JavaScriptfor ... inloop in disguise. Anindexoption in the CSfor ... inloop make sense because you're iterating over something inherently ordered; anindexwhen iterating over an object makes less sense because objects are inherently unordered so the index has no useful relation to what you're iterating over.