Transcript from the "Array-Like Object" Lesson
>> Great. So we're gonna talk about the arguments array like objects a little bit more. But first, let's run this code to see what happens. Who wants to go first? Someone probably wants to go first because there's a crazy line here. So, whoever goes first doesn't have to do that line.
[00:00:20] What's the very first thing that happens in this code block?
>> So, declare a const variable and give it a function.
>> Yep. So, we're creating this definition somewhere in memory. Great, which way do you wanna go? Left or right? Who do you like better?
>> Just kidding.
>> I'm gonna go with my guy, Ben over there
>> We're gonna skip, okay
>> He is in my fantasy football team league.
>> I lost him last time so, yeah.
>> And just so you know it's gonna go this way now. So be prepared, did you see that then it's gonna go.
>> So we just jumped over the declarations all right?
>> Yep so we jumped over the function body and now we're-
>> Now we are currently calling the constructArr function with the passing the arguments was, it, in.
>> Okay, Dan.
>> The question is what is running next?
>> Yeah, what happens next?
>> [INAUDIBLE] function body [INAUDIBLE]
>> Yep, so we'll jump into the function body. And then what happens.
>> Variables declared [INAUDIBLE]
>> Yep, we declare a variable arr and we assign it to something crazy. Brian, do you want to take a stab at what's happening.
>> So you assign it to the arguments that were called was, it, in. But prototype slice, when you could create a slice of an array somehow but I'm not really sure what mechanically happens with that one.
>> Yeah. A little bit crazy. What this does is it will take an array like object and turn it into an array.
[00:02:24] So basically, what it's doing is it referencing the slice method that comes with arrays and passing it that, it's passing it the argument pseudo array as the context and as a result of that, it turns an object like an array like object into an array array. If that makes sense.
[00:03:01] You don't have to understand what this stuff is doing. Just know that this craziness is gonna turn this arguments object into an array. Yeah, cool. And then-
>> Is this the canonical way of doing that, of taking that pseudo arguments array?
>> Has anyone done it a different way?
[00:03:29] Yeah, this is the way I've always done it. Okay, so array is now an array that looks like what? Let's just [INAUDIBLE] It's not how it's supposed to work, okay. So what does arr look like at this point, Jenny? You gonna write it out for us.
>> What does it look like at this point?
>> I don't know what to say right now. [LAUGH]
>> Sure. So, do you remember what happened here in this craziness?
>> Yeah, so it took the string looking array and turned it into an array.
>> Yeah, and so what does that array look like?
>> So it's got the brackets.
[00:04:15] And then was, it, in. You have separate pieces of there in.
>> Yep. Exactly, cool. And then, Josh, what happens next?
>> Push the billiards room onto that array.
>> Push to the end.
>> What's that?
>> Push it to the end.
>> Yeah, so now we have an array that looks like this.
[00:04:47] The billiards room. And then what are we gonna return?
>> You do some manipulation with the join array.
>> So the join method is a native array method that's going to take all of the indices and join it with whatever character you give here. So I just put a space.
[00:05:16] So it's gonna join it with the space. So it'll say was it in the billiards room? So that's what we just did. How do we feel about that, it makes sense? Any questions about anything in there?
>> Is it returning a string?