There are multiple ways to work with an array and this works similar to how an array works in JavaScript. You can also declare an array using generics:
let a: number[] = [1,2,3];
let b: Array<number> = [1,2,3];
let c: Array<any> = ['Hello',10];
Here we make use of the for of loop to iterate over the elements in the array, and print each element. Next, we loop again, but using the forEach function:
var numArray = [1, 2, 3];
for (let item of numArray) {
console.log(item); //Produces: 1,2,3
}
//Using forEach to get same output as above
numArray.forEach(element => {
console.log(element);
});
Similar to using a stream() and map() in Java, we can use the map function available to produce a new result which processes each element within the array:
let priorities = ['low', 'medium', 'high'];
let priorityUpperCase = priorities...