Array Iteration

👨‍💼 We need to process our inventory data. Let's practice different ways to iterate over arrays.
🐨 Open and:
  1. Use for...of to log each product
  2. Find all products that are in stock
  3. Count products over a certain price
💰 for...of with type inference:
for (const product of products) {
	// TypeScript knows product is { name: string, price: number, ... }
	console.log(product.name)
}
💰 Building a filtered list:
const inStock: ProductType[] = []
for (const product of products) {
	if (product.inStock) {
		inStock.push(product)
	}
}

Please set the playground first

Loading "Array Iteration"
Loading "Array Iteration"
Login to get access to the exclusive discord channel.