array.foreach typescript code example

Example 1: foreach typescript

example() {
    for (let item of this.items) {
        if (true) {
            return;
        }
    }
    // Do stuff in case forEach has not returned
}

Example 2: foreach typescript

for (let item of this.items) {
        if (true) {
            return;
        }
    }

Example 3: typescript foreach

let num = [7, 8, 9];
num.forEach(function (value) {
  console.log(value);
});

Example 4: for each array javascript

var fruits = ["apple", "orange", "cherry"];
fruits.forEach(getArrayValues);

function getArrayValues(item, index) {
  console.log( index + ":" + item);
}
/*
result:
0:apple
1:orange
2:cherry
*/