24 lines
478 B
JavaScript
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)
|
|
}
|
|
|
|
|