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

new Array();

Creating our first array and seeing its initial size using the 'length' property.

Video Transcript

00:00So I'm going to open up my main, and I'm just going to jump right into my class.
00:07And in my class itself, what I want to do right now, I want to just create a quick object
00:10just to show one more time what an associative array is.
00:13So we would create an object, we'll just define it as an object, and then we ask to
00:18create a new, and then we set it again, new object, and open and close bracket.
00:24Now if you're working with an older version of Flash, you might not get all the hints,
00:27just type it on, and just make sure that your syntax is exactly the same.
00:31So when you're saying new, it's all in lower case, and when we're typing object,
00:35because it's a class, we have to make sure that its name exactly matches up
00:39to the name that's in the reference.
00:40And in this scenario, we always start with an uppercase
00:43when we're working with classes, and then we camel case it.
00:47And for example, a movie clip which we have here already set,
00:49which is a visual element, which is a type of object as well, like we've said.
00:54We could see that our movie clip has an uppercase M and an uppercase C.
00:58Okay, so now we created our object, and we said that we could create
01:01associative arrays with objects by just opening a bracket, typing inside here
01:06something, such as let's say Ben, and then setting, for example,
01:10we set a password, one, two, three, four, and maybe we had another user
01:15that had a different password, and let's say that user was John.
01:20Well, let's say it's Jill, and we're going to set Jill a password,
01:27and we're going to give her a password of 5555.
01:31Okay, so that was associative arrays.
01:33Everybody know what they are.
01:35So what are arrays? What is the point of an array,
01:37and how does it stand out versus an associative array?
01:41An associative array order is really not relevant.
01:44That that I typed Ben first or Jill first, it really didn't matter.
01:48It really was do basically associations.
01:50We put inside associations and created an object,
01:52which is basically a bucket with keys and values.
01:56An array is very similar to that.
01:58It just adds one more rule to that.
02:00Instead of working with strings, we're going to work with numbers,
02:03and not only we're going to work with numbers, those numbers are indexed.
02:07So it's basically there's an order connected to our list.
02:12And there's a lot of scenarios in programming,
02:14and not only in programming in real life as well,
02:17that order is important.
02:19And when order is important, arrays come
02:21and they're perfectly matched for orderly things.
02:24So let's look at an example.
02:25First of all, let's see how we create a new array.
02:28So I'm just going to comment out our object here.
02:31This is our reference for an associative object.
02:34And what I want to do next is I want to open up a new array.
02:38An array works in a very similar way.
02:40So I'm just going to create a new variable.
02:41I'm just going to call it a for now for array array.
02:45And again, I'm going to put a colon,
02:47and I'm going to type then array again.
02:50Open a bracket, close a bracket, and we've just created a new array.
02:56Now let's check how many things are in our array,
02:58because we didn't put anything into our array.
03:01By default, arrays come with one property that we could always call.
03:04So for example, in this scenario, we're just going to call our array object,
03:10and we're going to ask for its length.
03:13And if we run our application now, we should see that our array has been created,
03:16but the output that we'll get should be 0, because we have no content in our array.
03:21And here we go.
03:22So we have a new array.
03:23It's an index, although we didn't put anything inside of it.
03:26And we know we've created a new bucket.
03:28And this bucket is organized, so now we know how many things are in that bucket.
03:32And we know that right now our bucket contains 0.

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!