02Geek HTML5 and JavaScript, TypeScript, React, Flash, ActionScript online School
Previous VideoNext Video

Associative Arrays

Associative arrays are not far away from what we where doing so far and actually are very closely tied together. an associative array is a key value relationship . aka we send in a key we get a value back. - lets see it in action in this short video.

Video Transcript

00:00All righty, so we just finished and before I even say that,
00:04I created a new empty file,
00:0603Arrays, which you can find in your source code.
00:09Again, if you open up the source code,
00:10you'll find it in its final resolution,
00:13if not create your own file and start working with me.
00:17All right, so we've learned about objects.
00:19We've seen a few different variations of the object.
00:21We've seen the date,
00:22which is a more sophisticated one that had
00:24pre-created things within it.
00:26We've seen the object on which we
00:28created our own little helper functions for ourselves.
00:32Now we're ready to move on to a really cool type of object,
00:35which is called an array or an,
00:37well, it's called an array, not or.
00:40An array is basically an indexed way of storing data.
00:43It's basically a queue.
00:45Objects on the other hand are associative.
00:48What does that mean associative?
00:50Then until now when we worked with our objects,
00:52and if I create an object really quickly,
00:54and I create a new property,
00:58let's say called name, and I'll just put there my name.
01:02All right, so created variable.
01:04Now the association, associated array means
01:07we basically, to access this variable,
01:10we need to send this association.
01:12We've used the dot syntax.
01:14Although there's one more way of doing it,
01:15and the second way of doing it
01:17is basically the way that's called an associative array.
01:19And the way that it's done is to approach it
01:21or to create it is basically,
01:23and I'm gonna do this quick alert again,
01:25is basically just saying we wanna go to our object,
01:28and then we open a, well, how do you call this bracket?
01:32Squared bracket, and then we put inside of it a string
01:36that represents our variable.
01:38That string is our name, which by the way,
01:40this is a really cool way of doing stuff
01:42because then you could dynamically create the name, right?
01:44There's a lot of ways of doing stuff
01:46that you just can't do if you just approach stuff
01:48always with the dot syntax.
01:50We're not gonna dig too deep into that right now
01:52because it's a very advanced way of programming,
01:55and a very fun way, by the way.
01:56But for our sake and purpose, we wanna see this
01:59because we wanna kinda tie in the connection.
02:01Until now, all of our names were strings,
02:04which are our variables.
02:06We couldn't start with a number
02:07because if we started with a number,
02:09that's an illegal variable type.
02:11You can't start a variable with a number.
02:12You always start it with a character,
02:17or one, you know, like I don't like,
02:19I'm not gonna tell you that you're allowed
02:20to use the dollar sign
02:21because I hate it when people do that.
02:23So that doesn't exist, okay?
02:25Now, although you could,
02:26I just don't want you to do it.
02:27I don't like doing it.
02:28I hate it when people do it.
02:29It's too, you know, that belongs to PHP.
02:32That doesn't belong to us.
02:34All right, so that way we could have
02:36approached our variable, and if we wanted to,
02:38we could have tested it out
02:39and did a little refresh here,
02:41and we would see that we would get our name as well
02:43without using the dot syntax.

Ready to Level Up Your Skills?

Join thousands of learners on 02GEEK and start your journey to becoming a coding expert today!

Enroll Now for Free!