Transcript
00:00 Hey, everybody. It's time to talk about arrays. Arrays are basically like if if we think about objects as being a basket that has a bunch of things inside, arrays are a special kind of basket that have those things in special compartments that are numbered. So you can always reach in and grab the first one and grab the second one, and and, and then whatever is inside of that, who knows. So arrays are still an object.
00:22 It's still like a basket, but it it's just got numbered items in it. So, this is the basic syntax for making an array. Here's our array of numbers, array of number, and one, two, three, four, five. If we were if we were to try to stick something in there that's not a number, we're gonna get a type error. And then here's our array of names and array of strings.
00:40 There are actually two syntaxes for the types of this thing, for the TypeScript portion, and that is this number with the bracket syntax, which is shorter, but the array syntax is called a generic. This syntax is preferred for a variety of reasons. I've got a blog post that, linked that you can go take a look at. It's just a lot better. So definitely prefer, the array syntax.
01:05 But if you want to go with this or if you're lots of AI agents will go with this, syntax, it's perfectly fine. It just bugs me because the readability is like the biggest annoyance. It's a number array. No. No.
01:19 No. It's an array of numbers. That makes more sense. And especially if you're talking about, an array that can have multiple different types of things in it, then it gets really messy and super annoying. Okay.
01:31 So as far as type safety is concerned, once you have that type in place, then it ensures that you can only push the right types of things into it, which, by the way, you can, add items to an array with the push method. There are actually other ways that you can add items to an array. But, yeah, the push is what we're gonna be doing today. And, if you had mixed types, an array with multiple different kinds of things, then you use this union, syntax, which we haven't really talked about yet, but you'll get to that eventually. Don't worry.
02:02 Alright. With that, I think you have enough that, for you to get going on with. So get going on, and we'll see you in the exercise.
