1
00:00:00,360 --> 00:00:01,440
Hello, how's it going?

2
00:00:01,470 --> 00:00:07,920
We're almost finished our email extractor application, there's a few things that we do need to be mindful

3
00:00:07,920 --> 00:00:11,070
of and one of them is we're moving out of the duplicates.

4
00:00:11,340 --> 00:00:16,070
So we see that we've got eight emails found, but we know that all I did was duplicated the string value.

5
00:00:16,230 --> 00:00:17,460
So those are all duplicates.

6
00:00:17,460 --> 00:00:20,040
So it should still only be outputting the four emails.

7
00:00:20,340 --> 00:00:23,510
And let's do that and we'll fix that within this lesson.

8
00:00:23,820 --> 00:00:28,620
So setting up an array, so basic empty array, we can call that holder.

9
00:00:29,040 --> 00:00:32,400
And what we're going to do is we're going to loop through that array.

10
00:00:32,700 --> 00:00:34,710
So doing just a regular for loop.

11
00:00:34,950 --> 00:00:42,120
So letting X equals zero looping through while X is less than email data length and then incrementing

12
00:00:42,120 --> 00:00:47,090
X so that we have a way out of our loop, or are we going to loop through and add to Holder.

13
00:00:47,100 --> 00:00:49,980
So taking Holder and using push method.

14
00:00:50,010 --> 00:00:57,060
So what that does is it adds the content into the new array and taking that email data array, we're

15
00:00:57,060 --> 00:01:01,500
going to push whatever the active element is and add that into the array.

16
00:01:01,710 --> 00:01:04,530
So basically what this is done is this is duplicated the array.

17
00:01:04,530 --> 00:01:08,610
So now we've got another record holder with the exact same details.

18
00:01:08,760 --> 00:01:14,850
And what we want to do is before we actually added into Holder, we want to do a quick check to see

19
00:01:14,850 --> 00:01:23,340
if it already exists so we can take our Holder array and check to see index of and what index of does

20
00:01:23,340 --> 00:01:28,590
is it can check the array to see if there's an index value for a particular value.

21
00:01:28,590 --> 00:01:33,270
And if there is, that's going to turn dark, that index value, otherwise it's going to return back

22
00:01:33,270 --> 00:01:34,170
negative one.

23
00:01:34,570 --> 00:01:44,160
So we're checking to see if the value of email data X exists and if it does exist that we know we've

24
00:01:44,160 --> 00:01:50,040
got an index value being returned back and if it doesn't exist, that we've got a negative one being

25
00:01:50,040 --> 00:01:50,730
returned back.

26
00:01:50,910 --> 00:01:54,580
So negative one means that it's not in the array already.

27
00:01:55,110 --> 00:02:02,220
So now we've got a nicely formatted brand new array and this time we've removed out the duplicates.

28
00:02:02,220 --> 00:02:06,090
So we do get emails and now we're using that holder array.

29
00:02:06,330 --> 00:02:11,700
So it doesn't matter how many that I put in there, we're still outputting that holder array.

30
00:02:11,820 --> 00:02:17,090
And there's one thing that we need to still update here as well, and that's outputting that value there.

31
00:02:17,100 --> 00:02:24,660
So now it doesn't matter how many times these emails appear within that string value, we're still only

32
00:02:24,660 --> 00:02:28,110
extracting out the unique ones, the unique emails from the string.

33
00:02:28,740 --> 00:02:34,740
One last thing that we can do, and sometimes the user might not want to have it comma separated.

34
00:02:34,920 --> 00:02:36,780
We might want to have another separator.

35
00:02:37,020 --> 00:02:39,330
And that's also easy to do with JavaScript.

36
00:02:39,510 --> 00:02:45,180
So because this is an array and we're putting it within our visible area, turns it into a string,

37
00:02:45,180 --> 00:02:47,910
and by default we know that there is a comma separated.

38
00:02:48,030 --> 00:02:49,740
So that's why it's comma separating it.

39
00:02:49,950 --> 00:02:51,480
So there's another way to do that.

40
00:02:51,480 --> 00:02:57,540
And we can create a different type of separator by using the joint method in JavaScript.

41
00:02:57,810 --> 00:03:00,600
So let's create that and temp holder.

42
00:03:01,140 --> 00:03:03,530
This can be called whatever we want it to be called.

43
00:03:03,540 --> 00:03:06,970
We could also output it directly within that inner text if we wanted to.

44
00:03:07,260 --> 00:03:13,590
So we're taking our holder and we're using the joint method, so joins all elements of an array into

45
00:03:13,590 --> 00:03:14,180
a string.

46
00:03:14,190 --> 00:03:19,380
So by default, if we do join Kharma, we're not going to actually see anything different.

47
00:03:19,390 --> 00:03:20,670
I'm going to use double quotes there.

48
00:03:21,090 --> 00:03:24,750
So these are just quotes around whatever the separator that we want.

49
00:03:24,960 --> 00:03:26,310
So we're not going to see anything different.

50
00:03:26,610 --> 00:03:31,710
But for instance, if we are to have a semicolon outputting there, sometimes that's a useful way.

51
00:03:31,860 --> 00:03:37,960
You can see that now instead of the comma or I need to put that temp holder, of course.

52
00:03:37,980 --> 00:03:38,880
So refresh.

53
00:03:38,880 --> 00:03:40,920
And we can see that now instead of the comma.

54
00:03:41,040 --> 00:03:43,140
We've got the colon there, the semicolon.

55
00:03:43,620 --> 00:03:44,880
So this can be anything.

56
00:03:44,880 --> 00:03:49,230
We could have a bunch of dashes new and whatever we want.

57
00:03:49,860 --> 00:03:54,210
And of course, probably you don't want to do this, but this is always an option.

58
00:03:54,570 --> 00:04:00,090
So I'm going to leave it as a semicolon and then it's up to you to extend on this if you want if you

59
00:04:00,090 --> 00:04:01,500
want to have a different separator.

60
00:04:01,650 --> 00:04:06,880
And all this is doing, again, this is manipulating the arrays, using JavaScript.

61
00:04:06,880 --> 00:04:12,090
So this is an array method where we can join the array together, turn it into a string, and we can

62
00:04:12,090 --> 00:04:17,580
specify what we want as the separator between the items that were contained within the array.

63
00:04:17,700 --> 00:04:20,100
So now we've got the number of emails that were found.

64
00:04:20,280 --> 00:04:27,510
We've got the length and we've also got them as unique values are being returned and we're also changing

65
00:04:27,510 --> 00:04:28,830
and updating the joiner.

66
00:04:29,250 --> 00:04:31,790
So go ahead and add this into your application.

67
00:04:32,160 --> 00:04:35,160
Try it for yourself, have some fun with it, experiment with it.

68
00:04:35,430 --> 00:04:39,750
And next, we're going to do a quick code review of our email extractor.

69
00:04:39,750 --> 00:04:40,740
So it's coming up next.

70
00:04:40,950 --> 00:04:46,920
So go ahead and add this into your project, the ability to get the unique emails as well as to change

71
00:04:46,920 --> 00:04:49,980
the separator for the emails that are being output for the user.
