create a loop of fruits in javascript

You can create an array of fruit names and then use a for loop to iterate over the array and do something with each element. Here's an example:

index.tsx
const fruits = ['apple', 'banana', 'pear', 'orange'];

for (let i = 0; i < fruits.length; i++) {
  console.log(fruits[i]);
  // Do something else with each fruit here
}
169 chars
7 lines

This will loop over the fruits array and log each fruit name to the console. You can replace the console.log statement with any other code you want to execute for each fruit.

related categories

gistlibby LogSnag