1
00:00:00,390 --> 00:00:04,890
We saw in the last lessen some of the really neat things that you can do with the race, so there are

2
00:00:04,890 --> 00:00:07,920
even more things that you can do, such as sorting them.

3
00:00:07,920 --> 00:00:14,940
You can reverse sort them, you can concatenate them together as well as find objects in the array.

4
00:00:15,090 --> 00:00:19,080
And we also looked at index of we're going to look at that in a little bit more detail.

5
00:00:19,530 --> 00:00:24,270
So, again, going back to what is available at the Mozilla Developer Network.

6
00:00:24,540 --> 00:00:31,260
So if you go into the page, you can see on the left hand side, there's all of these different methods

7
00:00:31,260 --> 00:00:33,030
that are available with arrays.

8
00:00:33,360 --> 00:00:35,400
You can join them, you can reverse them.

9
00:00:35,580 --> 00:00:39,340
So we are going to be looking at some of these in more detail in this lesson.

10
00:00:39,720 --> 00:00:43,690
So here's a code snippet and we've got a couple of different arrays.

11
00:00:44,010 --> 00:00:47,630
So what we're doing is first we're sorting them, then reverse sorting them.

12
00:00:47,820 --> 00:00:52,170
So that will reorganize and reorder these arrays.

13
00:00:52,170 --> 00:00:54,270
And the values are contained within the arrays.

14
00:00:54,840 --> 00:00:58,270
Also looking at to check to see if there's an index value.

15
00:00:58,530 --> 00:01:01,800
So this is where we're returning back a value of negative one.

16
00:01:01,810 --> 00:01:06,630
So that means it's not found in the array joining to arrays together.

17
00:01:06,630 --> 00:01:11,040
So we've got my array concat, rounded brackets, my array two.

18
00:01:11,040 --> 00:01:18,090
So that's joining those two arrays together to form a new array or outputting that as well as checking

19
00:01:18,090 --> 00:01:22,150
to see if an element is available within the array.

20
00:01:22,170 --> 00:01:25,270
So we're finding it and returning that element.

21
00:01:25,290 --> 00:01:31,380
And we can also add in and have a condition there to check to see if the element is greater than 10.

22
00:01:31,380 --> 00:01:37,850
Then we return that value and we can also output that found value as well into the console.

23
00:01:37,860 --> 00:01:44,010
So find is also really powerful because it gives us the ability to find items that are contained within

24
00:01:44,010 --> 00:01:46,200
the array and return them back.

25
00:01:46,230 --> 00:01:50,100
So this is going to return back the first item within find.

26
00:01:50,430 --> 00:01:53,630
There's more information, of course, Mozilla Developer Network.

27
00:01:53,880 --> 00:01:57,870
So within their example, they have Horeb, all different numbers in there.

28
00:01:58,050 --> 00:02:02,610
And we're looking to see to find if the value of the element.

29
00:02:02,880 --> 00:02:05,000
So we notice that we've got a function in there.

30
00:02:05,280 --> 00:02:08,480
So we're got an argument that's being passed into the function.

31
00:02:08,520 --> 00:02:11,160
So all of the different values are contained within the array.

32
00:02:11,190 --> 00:02:14,370
It will return back the first one that it finds that's greater than 10.

33
00:02:14,520 --> 00:02:19,770
So in this case, it found 12 and that's where we get an output of 12 is the challenge of the lesson

34
00:02:19,770 --> 00:02:21,540
is to transform the array.

35
00:02:21,780 --> 00:02:24,990
So try out the different methods, sort in reverse.

36
00:02:25,020 --> 00:02:30,780
Also combine two different arrays together with the CONCATENATE method and then search the array for

37
00:02:30,780 --> 00:02:36,870
a number and return a value that matches that number that is greater than the one that we're trying

38
00:02:36,870 --> 00:02:37,400
to find.

39
00:02:37,740 --> 00:02:43,710
And you can also console log out the elements as you're iterating through and you can see what gets

40
00:02:43,710 --> 00:02:45,150
output into the console.

41
00:02:45,180 --> 00:02:46,720
So go ahead and try this out.

42
00:02:46,770 --> 00:02:53,640
So let's start with the default where we've got to arrays, then console log out the my array, then

43
00:02:53,640 --> 00:02:55,080
taking my array.

44
00:02:55,470 --> 00:02:56,860
We're going to sort it.

45
00:02:57,030 --> 00:03:00,510
And then also we're going to output the array after the sort.

46
00:03:00,840 --> 00:03:02,160
So see what the differences.

47
00:03:02,370 --> 00:03:07,140
And as you can see, when it gets sorted, it gets sorted with numbers first.

48
00:03:07,140 --> 00:03:13,860
So the numbers starting at the lowest to the highest and then it starts alphabetically sorting the array

49
00:03:13,860 --> 00:03:18,130
items from a all the way to W.

50
00:03:18,180 --> 00:03:20,940
So all of those gets sorted alphabetically as well.

51
00:03:21,180 --> 00:03:25,180
So that's what sort does you can also do our reverse sort.

52
00:03:25,650 --> 00:03:31,310
So that's another option where you can reverse the order of the items in the array.

53
00:03:31,620 --> 00:03:36,360
And what this will do is this will do actually the opposite of sort of last one.

54
00:03:36,370 --> 00:03:43,950
So starting with alphabetically w all the way down and then starting with numbers, we're going all

55
00:03:43,950 --> 00:03:45,150
the way down with the numbers.

56
00:03:45,450 --> 00:03:48,950
Let's check to see if it contains a value.

57
00:03:49,410 --> 00:03:56,310
And this is where we can use the index of again where we've got the my array and checking to see index

58
00:03:56,310 --> 00:04:00,010
of the value that we're going to look for, for the index.

59
00:04:01,260 --> 00:04:03,260
So how about we look for hello?

60
00:04:03,270 --> 00:04:08,430
And if the index value is negative one because it's an index of negative one.

61
00:04:09,400 --> 00:04:14,770
So if we say that it's not equal to negative one, we see that we've got item found.

62
00:04:14,920 --> 00:04:16,810
Update this to the world.

63
00:04:16,820 --> 00:04:19,810
How about we call it World two and refresh?

64
00:04:19,810 --> 00:04:20,920
We get not found.

65
00:04:21,370 --> 00:04:24,850
Let's create a new array joining to a race together.

66
00:04:25,450 --> 00:04:29,110
So we've got a variable that we're going to declare a new array.

67
00:04:30,280 --> 00:04:39,130
So taking the mihiri and then using concat concat will allow us to join the two arrays together and

68
00:04:39,130 --> 00:04:45,460
if we can't so log out the new array value, you're going to see that those are both arrays that are

69
00:04:45,460 --> 00:04:46,210
joined together.

70
00:04:46,220 --> 00:04:47,590
So it's a really long array.

71
00:04:47,590 --> 00:04:50,470
Got 15 items in length there for this array.

72
00:04:50,770 --> 00:04:58,840
So do let found and then the array that we want it to search so we can use that my array and looking

73
00:04:58,840 --> 00:05:05,470
at find that we've got the function and we've got an element as the value that we're passing in.

74
00:05:05,620 --> 00:05:10,520
So we can see that and then we'll also return if L is greater than 10.

75
00:05:10,750 --> 00:05:12,460
And so this isn't the numeric race.

76
00:05:12,480 --> 00:05:17,460
So maybe first we'll try the numerical and then we'll try the other one afterwards.

77
00:05:17,890 --> 00:05:25,450
So see, what happens here is that as we loop through the array values, so once it hits a value that's

78
00:05:25,450 --> 00:05:26,860
over 10, then it stops.

79
00:05:27,430 --> 00:05:33,460
So if this value let's add in a few other ones now we can see it goes through all of the different values.

80
00:05:33,470 --> 00:05:35,250
So it starts at five.

81
00:05:35,260 --> 00:05:39,200
It looks at it's got an undefined because I've got a blank space there.

82
00:05:39,340 --> 00:05:45,460
So essentially what it's doing is it's looping through until it finds the one that matches the criteria

83
00:05:45,460 --> 00:05:46,450
that we're searching for.

84
00:05:46,780 --> 00:05:50,980
And that's how you can use find in order to return back values.

85
00:05:51,250 --> 00:05:58,450
So if we try the find on my array, you can also see that it goes through all those values.

86
00:05:58,630 --> 00:06:04,240
So it is looking at all those values until it finds one that has a value of ninety nine.

87
00:06:04,360 --> 00:06:07,250
And when it does, then that's the one that returns back.

88
00:06:07,270 --> 00:06:11,740
So first one to meet the criteria then that's the one that gets returned back.

89
00:06:12,070 --> 00:06:17,380
If we don't meet the criteria for looking for over one hundred, you're going to see that it's going

90
00:06:17,380 --> 00:06:19,440
to logout that undefined.

91
00:06:20,020 --> 00:06:23,200
So it loops through all of them and it returns back undefined.
