Mental Model
Go through each item in the list one by one to check or change it.
Analogy: Like walking down a line of mailboxes, opening each one to see what's inside.
Index: 0 1 2 3 4
Array: [5]->[3]->[8]->[1]->[7]
↑Index: 0 1 2 3 4
Array: [5]->[3]->[8]->[1]->[7]
↑Index: 0 ↑ 1 2 3 4 Array: [5]->[3]->[8]->[1]->[7]
Index: 0 1 ↑ 2 3 4 Array: [5]->[3]->[8]->[1]->[7]
Index: 0 1 2 ↑ 3 4 Array: [5]->[3]->[8]->[1]->[7]
Index: 0 1 2 3 ↑ 4 Array: [5]->[3]->[8]->[1]->[7]
Index: 0 1 2 3 4 ↑ Array: [5]->[3]->[8]->[1]->[7]
Index: 0 1 2 3 4 ↑ Array: [5]->[3]->[8]->[1]->[7] Printed values: 5 3 8 1 7
class ArrayTraversal { static traverseAndPrint(arr: number[]): void { for (let i = 0; i < arr.length; i++) { console.log(arr[i]); } } } const inputArray = [5, 3, 8, 1, 7]; ArrayTraversal.traverseAndPrint(inputArray);
for (let i = 0; i < arr.length; i++) {console.log(arr[i]);for (let i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i++) { console.log(arr[i]); }arr using a for-of loop in TypeScript?const arr = [10, 20, 30];
let result = [];
for (let i = arr.length - 1; i >= 0; i--) {
result.push(arr[i]);
}
console.log(result);arr:const arr = [1, 2, 3];
for (let i = 0; i <= arr.length; i++) {
console.log(arr[i]);
}arr of numbers, which code snippet correctly creates a new array containing only the even numbers from arr using array traversal?Pass the test and this pattern moves unknown