This post we will discus how to get item in a specific index using js
Method one is using Array.at()
More information on this method can be fount here.
let arr = ["apple", "strawberry", "banana", "cherry"];
//array starts with 0
let pos2 = arr.at(1) // strawberry
let pos100 = arr.at(100) // undefined as array length is less than 100
Method two is using Array[index]
let arr = ["apple", "strawberry", "banana", "cherry"];
//array starts with 0
let pos2 = arr[1] // strawberry
let pos100 = arr[100] // undefined as array length is less than 100
Comments
Post a Comment