Is there a way to dynamically loop through Pug variables with javascript?
I can successfully statically loop through Pug variables with the each.. in
function but may need to rerun the loop pending on other actions
With a variable groups
, I can successfully get the first Object and property in the array like this
"#{groups[0].group_name}"
And successfully the length of the array
"#{groups.length}"
The rest of these codes do not work, this one just logs [object Object] one line at a time.
script.
for(k in "#{groups}"){
console.log("#{groups}"[k]);
}
I get an Uncaught SyntaxError: Unexpected identifier
script.
for(k in #{groups}){
console.log(#{groups}[k]);
}
"Cannot read property 'group_name' of undefined"
script.
for(i=0; i< "#{groups.length}"; i++){
console.log("#{groups[i].group_name}");
}
Also tried groups.forEach
, and groups.map
functions but no success. Any help would be much appreciated!!