To loop over an enum in JavaScript, you can use the for...in
loop. Here's an example:
index.tsx234 chars14 lines
In the above example, we define an enum called Fruit
and then use a for...in
loop to loop over its values. We use the hasOwnProperty
method to ensure that we only get the values that belong to the enum, and not any inherited properties. Finally, we log each value to the console.
gistlibby LogSnag