Variable function parameter

I'm trying to figure out how to pass a parameter in a for loop, like so: for (let i = 0; i < mainhaul[0].length; i++) { createSingle( co2cols, 'Distance', distanceFix(mainhaul[0][i].emissions.distances.{type}._) ); } This loop sits in a function, which gets type as a parameter, that I'm trying to use to alter the distanceFix parameter, but I can't figure out to do it, or if I even can do what I'm trying to. A little worried I've fallen into an xy trap. Basically, the question is, is there syntax to allow me to insert a variable into distanceFix to replace {type}? I'm not even sure if I'm making sense at this point, feeling a little in over my head :p
4 Replies
Jochem
Jochem•11mo ago
distances[type] should work if I'm understanding what you're asking correctly
Nox
Nox•11mo ago
Yep, that seems to have done the trick, thanks! :) I tried distances.[type], assuming I needed the dot, but apparently not.
Jochem
Jochem•11mo ago
nope, the square brackets work as property accessors on their own 🙂
Nox
Nox•11mo ago
yeah, that makes sense :)