To access array elements in TypeScript using index, you can use square brackets notation.
In this example,
numbers
with integer values.2
using indexing numbers[1]
.let numbers: number[] = [1, 2, 3, 4, 5];
console.log(numbers[1]);
2
In this example,
fruits
with string values.let fruits: string[] = ['Apple', 'Banana', 'Orange'];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}
Apple Banana Orange
In this tutorial, we learned How to Access Array Elements using Index in TypeScript language with well detailed examples.