array items using index examples fix

pull/24/head
Patrick Njuguna 5 years ago committed by GitHub
parent d16e82245a
commit e8765bd580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -165,7 +165,7 @@ let lastFruit = fruits[3]
console.log(lastFruit) // lemon console.log(lastFruit) // lemon
// Last index can be calculated as follows // Last index can be calculated as follows
let lastIndex = len(fruits) - 1 let lastIndex = fruits.length - 1
lastFruit = fruits[lastIndex] lastFruit = fruits[lastIndex]
console.log(lastFruit) // lemon console.log(lastFruit) // lemon
``` ```
@ -179,7 +179,7 @@ console.log(numbers[0]) // -> 0
console.log(numbers[5]) // -> 100 console.log(numbers[5]) // -> 100
let lastIndex = numbers.length - 1; let lastIndex = numbers.length - 1;
console.log(numbers[lastIndex]) -> 100 console.log(numbers[lastIndex]) // -> 100
``` ```
```js ```js
@ -199,7 +199,7 @@ console.log(webTechs[0]) // -> HTML
console.log(webTechs[6]) // -> MongoDB console.log(webTechs[6]) // -> MongoDB
let lastIndex = webTechs.length - 1 let lastIndex = webTechs.length - 1
console.log(webTechs[lastIndex]) -> MongoDB console.log(webTechs[lastIndex]) // -> MongoDB
``` ```
```js ```js
@ -222,7 +222,7 @@ console.log(countries[0]) // -> Albania
console.log(countries[10]) // -> Kenya console.log(countries[10]) // -> Kenya
let lastIndex = countries.length - 1; let lastIndex = countries.length - 1;
console.log(countries[lastIndex]) -> // Kenya console.log(countries[lastIndex]) // -> Kenya
``` ```
```js ```js
@ -242,7 +242,7 @@ console.log(shoppingCart[0]) // -> Milk
console.log(shoppingCart[7]) // -> Sugar console.log(shoppingCart[7]) // -> Sugar
let lastIndex = shoppingCart.length - 1; let lastIndex = shoppingCart.length - 1;
console.log(shoppingCart[lastIndex]) -> // Sugar console.log(shoppingCart[lastIndex]) // -> Sugar
``` ```
### Modifying array element ### Modifying array element
@ -721,4 +721,4 @@ const webTechs = [
🎉 CONGRATULATIONS ! 🎉 🎉 CONGRATULATIONS ! 🎉
[<< Day 4](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md) | [Day 6 >>](#) [<< Day 4](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md) | [Day 6 >>](#)

Loading…
Cancel
Save