Files
AP-Computer-Principles-Archive/arrays/Example2.js
2025-10-27 12:26:06 -05:00

24 lines
478 B
JavaScript

// creating an array of strings
let animals = ["Zebra", "Koala", "Lion", "Elephan", "Eagle"]
// displaying the items stored in array animals using a for loop
for(let i=0; i<animals.length; i++)
{
let item = animals[i] // gets item at location i
console.log('Item ' +i +": " +item)
}
console.log()
// displaying the items using the for-in loop
for(let i in animals)
{
let item = animals[i] // gets item at location i
console.log('Item ' +i +": " +item)
}