Arrays

14 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€92.84
List Price:  €129.99
You save:  €37.14
£79.72
List Price:  £111.61
You save:  £31.89
CA$136.78
List Price:  CA$191.51
You save:  CA$54.72
A$151.39
List Price:  A$211.96
You save:  A$60.56
S$135.31
List Price:  S$189.45
You save:  S$54.13
HK$782
List Price:  HK$1,094.84
You save:  HK$312.83
CHF 90.72
List Price:  CHF 127.01
You save:  CHF 36.29
NOK kr1,086.02
List Price:  NOK kr1,520.47
You save:  NOK kr434.45
DKK kr692.51
List Price:  DKK kr969.54
You save:  DKK kr277.03
NZ$166.43
List Price:  NZ$233.01
You save:  NZ$66.57
د.إ367.25
List Price:  د.إ514.16
You save:  د.إ146.91
৳10,970.69
List Price:  ৳15,359.41
You save:  ৳4,388.71
₹8,349.28
List Price:  ₹11,689.33
You save:  ₹3,340.04
RM473.75
List Price:  RM663.27
You save:  RM189.52
₦123,487.65
List Price:  ₦172,887.65
You save:  ₦49,400
₨27,810.05
List Price:  ₨38,935.18
You save:  ₨11,125.13
฿3,685.75
List Price:  ฿5,160.20
You save:  ฿1,474.45
₺3,226.13
List Price:  ₺4,516.71
You save:  ₺1,290.58
B$507.56
List Price:  B$710.61
You save:  B$203.04
R1,844.45
List Price:  R2,582.31
You save:  R737.85
Лв181.73
List Price:  Лв254.43
You save:  Лв72.69
₩135,953.36
List Price:  ₩190,340.14
You save:  ₩54,386.78
₪371.93
List Price:  ₪520.72
You save:  ₪148.78
₱5,723.27
List Price:  ₱8,012.81
You save:  ₱2,289.54
¥15,446.23
List Price:  ¥21,625.34
You save:  ¥6,179.11
MX$1,686.59
List Price:  MX$2,361.30
You save:  MX$674.70
QR364.61
List Price:  QR510.47
You save:  QR145.86
P1,357.27
List Price:  P1,900.24
You save:  P542.96
KSh13,298.67
List Price:  KSh18,618.67
You save:  KSh5,320
E£4,771.52
List Price:  E£6,680.32
You save:  E£1,908.80
ብር5,739.13
List Price:  ብር8,035.01
You save:  ብር2,295.88
Kz83,660.29
List Price:  Kz117,127.76
You save:  Kz33,467.46
CLP$92,979.70
List Price:  CLP$130,175.30
You save:  CLP$37,195.60
CN¥708.73
List Price:  CN¥992.25
You save:  CN¥283.52
RD$5,799
List Price:  RD$8,118.84
You save:  RD$2,319.83
DA13,435.05
List Price:  DA18,809.61
You save:  DA5,374.56
FJ$224.49
List Price:  FJ$314.30
You save:  FJ$89.80
Q776.98
List Price:  Q1,087.80
You save:  Q310.82
GY$20,913.53
List Price:  GY$29,279.78
You save:  GY$8,366.25
ISK kr13,955.60
List Price:  ISK kr19,538.40
You save:  ISK kr5,582.80
DH1,002.03
List Price:  DH1,402.88
You save:  DH400.85
L1,771.31
List Price:  L2,479.90
You save:  L708.59
ден5,723.76
List Price:  ден8,013.49
You save:  ден2,289.73
MOP$804.66
List Price:  MOP$1,126.56
You save:  MOP$321.89
N$1,841.06
List Price:  N$2,577.56
You save:  N$736.50
C$3,679.48
List Price:  C$5,151.42
You save:  C$1,471.93
रु13,360.08
List Price:  रु18,704.65
You save:  रु5,344.56
S/372.58
List Price:  S/521.63
You save:  S/149.04
K386.69
List Price:  K541.38
You save:  K154.69
SAR375.01
List Price:  SAR525.03
You save:  SAR150.02
ZK2,716.50
List Price:  ZK3,803.21
You save:  ZK1,086.71
L462.07
List Price:  L646.92
You save:  L184.84
Kč2,322.93
List Price:  Kč3,252.20
You save:  Kč929.26
Ft36,116.11
List Price:  Ft50,564.01
You save:  Ft14,447.89
SEK kr1,084.61
List Price:  SEK kr1,518.51
You save:  SEK kr433.89
ARS$88,016.60
List Price:  ARS$123,226.76
You save:  ARS$35,210.16
Bs690.78
List Price:  Bs967.13
You save:  Bs276.34
COP$390,579.97
List Price:  COP$546,827.59
You save:  COP$156,247.61
₡51,141.53
List Price:  ₡71,600.19
You save:  ₡20,458.65
L2,469.47
List Price:  L3,457.36
You save:  L987.88
₲747,500.10
List Price:  ₲1,046,530.05
You save:  ₲299,029.94
$U3,819.50
List Price:  $U5,347.45
You save:  $U1,527.95
zł400.65
List Price:  zł560.93
You save:  zł160.27
Already have an account? Log In

Transcript

Hello, in this video we are going to cover arrays in JavaScript. So what is an array so you know where a variable is, it's quite simple one, four, or one, eight, you know, you could have any data in there, you could have an object in there, you could have a string doesn't matter. And you know, we can print this out, or simple stuff. And array is just a collection of values, they come with encoded via, like a collection of variables. And to create an array, we just do var name of the array. So this is our name.

And n equals square brackets, semicolon. And now this is where you put your values. And if you want a string, you know, you want to put an object or an object, you know, whatever you would put like literally here between the equals and the semi colons you can put here, I'm going to keep it simple. I'm having to move from zero then I didn't know what you just put comma 12345. And you know, you can add as many as you want to access these are new. So first two out 01 new console, log our name.

And you know what I'm gonna do, I'm actually gonna change these to 1020. The main reason is, I'll explain it is that they wouldn't work you might just cause a bit of confusion. If I do zero, index zero, as you can see prints at 10. So this is the reason that I was chained if I you know, did zero here is printed at zero and the next one, and I need a colon here. So let's duplicate this. Going over this.

Save refresh. So we get a 25 hadn't changed in value, you would have just got printed 01. And that's fine. That's exactly what we want, we might have 40 more, of course, confusion between, you know, this zero and the actual value zero, this zero is the index, you can think of it almost like the key, whereas the other zero was the value. So that's, we've got this chain, the so in this video, we won't get any conflicts. And you might be thinking, Okay, you know, six values equally not duplicated six times in a way you need, that's cool.

But why if you're writing 100 values, which you know, is more than logical, especially if you create one, from let's say, something like a database, and you get a lot of rows, a lot of data, how would you do that? How would you you know, is there an easy way of doing it? And you know, fortunately for us, there isn't. I'm joking. days away, and you can see the full loop so as an extra task of now what I'm going to show you now, but I'll recommend pausing the video, try to go yourself if you Need any help, feel free to come by. Okay, so I'm going to create a for loop, create a variable for the assign a value of zero person Cola, I'm gonna say while i is less than can guess, we want to do the length of this.

So this will be six, but we don't put a six wall directly here, we're going to say on a dotnet. So we're going to use a property of our array. And this will you know, get the length of it, which is pretty darn cool. And now we are going to say I love the color console dot log. Or name. I reload.

Oh, yeah. So you know 1020 3040 5060 and that is all really, really cool stuff. Okay, so there's a couple of other different ways that you can create an array. You can use it in A key word is one use the array object use. So you could say if you don't know the values yet, but you know how many you're going to have, you could do something along these lines. I'm going to show you why here.

I'll create a new array when this new array equals new array unless they want, so a lot of them so we don't know the values here, but we know there's gonna be 100 items in there. And let's say we use a for loop. And just to save time, I will copy this. copy that and put that here. Instead of printing it out like this. We just have a new array.

Hi. And we're going to replace what's up with Amina index or with what I'm going to put here. Let's put i squared. So let's just do it twins. I will preach Today I'm going to comment this out Just so you know, we can see exactly what's happening. Okay?

So we get 014. And you might think in, you know, in 100 you know, squared equal to this isn't that something like what 10,000 and you're right, it is 10,000. Remember, this is less than, and the last value at your array is always the size minus one because you start atrophy in the array at index zero. so this will be 900, this will be 99 times 99, which gives you this value, okay. So that is a novel way of creating the array. So there are a few different functions that we can use as well.

So we can use functions to essentially Add elements to the array. So what I'll do is I'll copy this down here. But before I actually print it out again, I do new array, dot push. And if I do push up and literally add an extra item, so for the sake, we'll save it, refresh, as you can see, if I scroll up so the first comic got printed out till now hello world at the end of it, but second time, there was a Hello World, because push literally is as the new element to the end of the array. So that is pretty cool. And as you can see, you can make some master data type.

They don't want to have to be number of strings in other languages for a lot of other programming languages. Arrays have to be, you know, one type of data type. But in JavaScript, a lot of things are pretty Don Knuth there are bunch of other functions that you can utilize like thought for nothing can get, you thought the elements of the array which is really useful to have a built in function like this, you can choose and get a function called to string, which converts it, even if it's not a string into a string. So like the numbers, for example, you can have a method called pop, which essentially just means remit will have a weapon they remember, remove the last element of the array and like this, so many of the methods as long as you understand what we've done so far, you'll be good to go.

I'll provide a link with the video so you can see all the different features. But before we wrap up, I want to show you one or two other options. So there's one two little little things. So what I'm going to do, well, I'm gonna do is console, log in So these are some extra e f six functions of your JavaScript functions and I'm going to do array dot Murphy. Okay or docx file index what is you know, waffle lists about 90 to one. Okay, so so new array dot find index Okay, so far so good while I'm missing a couple of lines Do not result on expecting So, new red dot point in the this is really really confusing.

So, let me think about why this is not working. Because this you know often you can get for work you know trying to do with this, this should just purely get the actual index instead of getting the element itself. So, if you have an element and you want to just be able to get the, that particular element, this should, you know, literally just access it. Find it Okay, cuz you got the you got the regular fine if I put in one one or function Oh, one isn't a function Why is this same one isn't a function. So I know it's Huh, do let me try something out just throw a monkey on that one. This is totally off it's a it's not a function which is just totally weird.

One other thing I'm thinking about right now, let me just sort of go back to the point in there. missing something here, small. keep getting all that should return indifferent zero but still doesn't return index zero. So finding next one x in x and that value equals zero Okay, that's fine. Nothing there we go. Okay, I made a couple of mistakes one, it needs to be in this you know format because if I were to do it in with the other one, our name you know, that's fine as well so I'll do me wrong value.

So yeah, sorry about that. Let's switch back Okay, so these are some new feature Ramadan Bronco, but okay. Oh good. So you choose array dot find index dot find. And then in here, this takes a slightly different set of, you know, parameter. So you're just saying, This is the value that you're trying to find in there.

Yeah. And you're assigning the thing. This is the value that you're actually trying to specifically check well, so you have this format, and then you put 9801 here. And the reason you have this sort of format is you might actually do some sort of crazier thing where you say, we know zeros in here. So you put the minus 01 This will return Yeah, I'm going a bit too complex yet. I'm confusing myself now.

I must save in the Musonda must really mess. Okay, my next point, the end Next instead of the value regular point, find the value and this format was x x, and then you put the value itself. So 9995 and 801 is that the last index of the array of size 100. The last index is n which is 100 minus one so it would be 99. So this is an ethics function. There are some other functions as well you can use a for in loop as well you know a for each loop to be able to loop over the array.

I recommend doing that the next task I'm going to provide a link that will show you all of the different features sorry about it. There are confusion here I was like all currently with the wrong array and we were the wrong value in there or the wrong you know, the format here or just all over the place. Sorry about that. We got to fix so it's great to see how to fix yourself, the fact watch it for seeing the next video.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.