Loading
Current section: 2. Arrays 5 exercises
solution

Iteration

Transcript

00:00 Okay. Let's get into it. We'll do a four loop here for of to log, through each one of these array, items in the array. Boom. There we go.

00:09 Bingo. Bingo. Bob's your uncle. Whatever you wanna say. Now, with that, we can now create an array of in stock products.

00:17 So we're gonna take, make an array of products. We'll call them in stock and then we'll loop over those and if the product is in stock, then we'll push that product onto our in stock products array and we'll console log that length. If we console log that, there's three of them. Let's just console log the whole thing. There it is.

00:36 Three items. These ones are the ones that are in stock. And we could do the opposite if they're not in stock. Now we've got two of those. So there you go.

00:43 That's nice. And then, we're gonna keep track of how many products that cost more than 50. So the expensive count, the number of expensive products, we're gonna loop over the products. And if the price is more than $50, then we're gonna say it was expensive. So we're gonna increment the expensive count by one.

01:02 This is the same as expensive count plus equals one which is the same as expensive count equals expensive count plus one. One of these I like to do better than the others and I think you know which one that is. So with that now we've got, these logs and we can export this of course and there we go. We are looping over arrays. We're making copies of the array or, copies with only specific items in the arrays.

01:28 There are easier ways to do or at least more terse ways to do what we're doing here, which we'll learn about later in the workshop. But, yeah. Four loops plus arrays, they're They like each other a lot and they're very nice and powerful together. So good job on this one.