1
00:00:00,630 --> 00:00:02,160
Hello and welcome him.

2
00:00:02,160 --> 00:00:08,190
This video he'll be introducing you to JavaScript arrays.

3
00:00:08,670 --> 00:00:21,870
What is an array an array is basically a structure that allows you to store multiple values in one single

4
00:00:22,200 --> 00:00:23,600
reference.

5
00:00:23,610 --> 00:00:33,630
Basically what that means is that it stores multiple values in a single variable.

6
00:00:33,630 --> 00:00:43,590
So an array is a special variable which can hold more than one value at a time in comparison to a variable

7
00:00:43,950 --> 00:00:47,580
that can only hold one value at a time.

8
00:00:48,540 --> 00:00:57,840
An example of an array is this here for example you create an array called my data and you use it equals

9
00:00:57,840 --> 00:01:00,510
two to assign the values.

10
00:01:00,510 --> 00:01:09,200
You can tell it's an array because the values of an array are enclosed in square brackets.

11
00:01:09,210 --> 00:01:13,570
Also you can have different data types in an array.

12
00:01:13,590 --> 00:01:23,690
In this example here of course put number and string data type and values in an array so let's create

13
00:01:23,900 --> 00:01:31,520
a simple array using our Web console to create an array.

14
00:01:31,580 --> 00:01:33,570
You have to create the variable first.

15
00:01:33,590 --> 00:01:42,680
So you just type in V A r to create or define a variable into a space followed by the name you want

16
00:01:42,680 --> 00:01:44,300
to call a variable.

17
00:01:44,300 --> 00:01:49,610
I'm going to call my my my data.

18
00:01:49,610 --> 00:01:55,040
You then use it equals to sign to create the array.

19
00:01:55,320 --> 00:02:03,230
I use the opening square brackets and you add the values or the elements in the array.

20
00:02:03,380 --> 00:02:07,220
You can mix data types in my example here.

21
00:02:07,220 --> 00:02:18,480
I'm going to mix the data type with a string and also a number sample a number and a shrink.

22
00:02:18,650 --> 00:02:26,090
I'm going to add another number and then I'll add another string.

23
00:02:27,020 --> 00:02:28,460
When you are using string.

24
00:02:28,550 --> 00:02:33,020
Don't forget to enclose them in quotes.

25
00:02:33,740 --> 00:02:41,500
And when you are using arrays you separate each of the elements in the array by a comma.

26
00:02:41,540 --> 00:02:46,110
You can see a comma here and comma here.

27
00:02:46,190 --> 00:02:52,180
Only the last value or element that does not require a comma.

28
00:02:52,940 --> 00:03:00,500
So now that we've created an array to call the array we just need to call it by his name which is my

29
00:03:00,500 --> 00:03:02,330
data.

30
00:03:02,330 --> 00:03:10,760
And it would display the information the information here tells you that we've got an array of four

31
00:03:11,030 --> 00:03:14,600
elements which is one two three four.

32
00:03:15,350 --> 00:03:18,090
And it gives you the values.

33
00:03:18,270 --> 00:03:23,650
If I expand this you will see all these figures here.

34
00:03:23,750 --> 00:03:25,820
They're known as index.

35
00:03:25,820 --> 00:03:31,640
The way you access the elements in an array is by the index.

36
00:03:31,640 --> 00:03:36,320
So the very first element of value as index 0.

37
00:03:36,410 --> 00:03:38,450
The next one will have index 1.

38
00:03:38,450 --> 00:03:49,460
And so you can see here index 0 belongs to 7 index 1 belongs to John index to belong to 70 index 3 belongs

39
00:03:49,460 --> 00:03:58,220
to Jane and so on tells you here the length of the array is 4 because it has four elements all values

40
00:03:58,640 --> 00:04:00,710
inside the array.

41
00:04:01,310 --> 00:04:14,150
So if I wanted to access JANE WALTON The way I would do that would be my data and then square brackets

42
00:04:15,110 --> 00:04:25,860
and I'll type in three pick up best the index for Jane press enter and see it's giving me the value

43
00:04:25,860 --> 00:04:33,690
of Jane because Jane has an index of three as you can see here from the index so always remember that

44
00:04:34,170 --> 00:04:42,030
when you're trying to access the values in an array you have to access them using the index and index

45
00:04:42,030 --> 00:04:53,430
starts from zero upwards when you work with arrays it is easy to remove elements and also add new elements

46
00:04:53,490 --> 00:05:07,770
to an array using a process called poppin and pushing if you want to add element you use a method called

47
00:05:08,450 --> 00:05:17,790
in to add an element and if you want to remove you use a method called popping so popping will remove

48
00:05:18,260 --> 00:05:28,320
and pushing will add an element to an array so let's add an element to our Harry and the way we do that

49
00:05:28,560 --> 00:05:36,460
we call the array by his name which is in my case is called my data.

50
00:05:38,490 --> 00:05:48,810
And then you add a dot and type typing push and then in parent sees you specify the value you're trying

51
00:05:48,810 --> 00:05:58,350
to push into the array let's say I'm trying to add a number 10 into the array and that press Enter so

52
00:05:58,350 --> 00:06:04,500
you can see now is now showing that the array has five values.

53
00:06:04,650 --> 00:06:15,990
So if I want to call this array a game called my data it will now show that the length is five you say

54
00:06:16,260 --> 00:06:20,640
because I've now added a new element which is as number 10 here.

55
00:06:21,210 --> 00:06:24,620
So if I expand that you can see the index.

56
00:06:24,990 --> 00:06:28,320
We've got a new index for four which is number 10.

57
00:06:29,220 --> 00:06:35,950
If I wanted to remove an element from array.

58
00:06:36,310 --> 00:06:47,660
OK so I can do that using the pop method the pop method will remove the value that I've just add.

59
00:06:47,730 --> 00:06:52,320
So let's remove the value I've just added for typing my data

60
00:06:57,060 --> 00:07:07,880
dot pop and this will remove the very last value I've just added on.

61
00:07:08,300 --> 00:07:11,990
Can see here tells me 10 has been removed so far.

62
00:07:11,990 --> 00:07:20,050
Now references are now issued go back to the original value which is an array of four.

63
00:07:20,420 --> 00:07:22,710
You can see here this is the original let's.

64
00:07:22,730 --> 00:07:29,030
That's basically how you can add can move an element from an array.

65
00:07:29,060 --> 00:07:34,380
So this concludes his brief introduction to JavaScript arrays.

66
00:07:34,460 --> 00:07:40,580
There are other types of arrays and there are so many things you can do using javascript array.

67
00:07:40,580 --> 00:07:45,970
This is just an introduction to what an array is.

68
00:07:45,980 --> 00:07:47,190
Thank you for watching.

69
00:07:47,240 --> 00:07:47,980
And by phone.
