Menu
Coddy logo textTech

Iterating Over Arrays

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 63 of 77.

Iteration means going through elements one by one in a sequence. With arrays, we can access each element systematically using different methods.

The most common way to iterate through an array is using a for loop together with the .length property:

let fruits = ["apple", "banana", "orange"];
for (let i = 0; i < fruits.length; i++) {
    console.log(fruits[i]);
}

Output:

apple
banana
orange
challenge icon

Challenge

Easy

Create a program that receives an array of strings as input (given), and prints a new array containing only the words longer than 5 characters

Cheat sheet

To iterate through an array, use a for loop with the .length property:

let fruits = ["apple", "banana", "orange"];
for (let i = 0; i < fruits.length; i++) {
    console.log(fruits[i]);
}

Try it yourself

let arr = inp.split(", "); // Don't change this line
// Write your code below
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals