In regular JavaScript, one can write a for loop using the for…of syntax. Is this possible with observablehq?
const array1 = [1, 2, 3];
for (const element of array1) {
console.log(element);
}
>Solution :
Not really. As explained in the tutorials, Observable is not [exactly] JavaScript.
In your case, you need to do two things:
First, there is no const, just make a cell with array1 value:
array1 = [1, 2, 3];
Then for the for loop, in a separate cell, put it between curly braces:
{
for (const element of array1) {
console.log(element);
}
}
That cell, of course, will return undefined:
