Hello, how's it going?
We're almost finished our email extractor application, there's a few things that we do need to be mindful
of and one of them is we're moving out of the duplicates.
So we see that we've got eight emails found, but we know that all I did was duplicated the string value.
So those are all duplicates.
So it should still only be outputting the four emails.
And let's do that and we'll fix that within this lesson.
So setting up an array, so basic empty array, we can call that holder.
And what we're going to do is we're going to loop through that array.
So doing just a regular for loop.
So letting X equals zero looping through while X is less than email data length and then incrementing
X so that we have a way out of our loop, or are we going to loop through and add to Holder.
So taking Holder and using push method.
So what that does is it adds the content into the new array and taking that email data array, we're
going to push whatever the active element is and add that into the array.
So basically what this is done is this is duplicated the array.
So now we've got another record holder with the exact same details.
And what we want to do is before we actually added into Holder, we want to do a quick check to see
if it already exists so we can take our Holder array and check to see index of and what index of does
is it can check the array to see if there's an index value for a particular value.
And if there is, that's going to turn dark, that index value, otherwise it's going to return back
negative one.
So we're checking to see if the value of email data X exists and if it does exist that we know we've
got an index value being returned back and if it doesn't exist, that we've got a negative one being
returned back.
So negative one means that it's not in the array already.
So now we've got a nicely formatted brand new array and this time we've removed out the duplicates.
So we do get emails and now we're using that holder array.
So it doesn't matter how many that I put in there, we're still outputting that holder array.
And there's one thing that we need to still update here as well, and that's outputting that value there.
So now it doesn't matter how many times these emails appear within that string value, we're still only
extracting out the unique ones, the unique emails from the string.
One last thing that we can do, and sometimes the user might not want to have it comma separated.
We might want to have another separator.
And that's also easy to do with JavaScript.
So because this is an array and we're putting it within our visible area, turns it into a string,
and by default we know that there is a comma separated.
So that's why it's comma separating it.
So there's another way to do that.
And we can create a different type of separator by using the joint method in JavaScript.
So let's create that and temp holder.
This can be called whatever we want it to be called.
We could also output it directly within that inner text if we wanted to.
So we're taking our holder and we're using the joint method, so joins all elements of an array into
a string.
So by default, if we do join Kharma, we're not going to actually see anything different.
I'm going to use double quotes there.
So these are just quotes around whatever the separator that we want.
So we're not going to see anything different.
But for instance, if we are to have a semicolon outputting there, sometimes that's a useful way.
You can see that now instead of the comma or I need to put that temp holder, of course.
So refresh.
And we can see that now instead of the comma.
We've got the colon there, the semicolon.
So this can be anything.
We could have a bunch of dashes new and whatever we want.
And of course, probably you don't want to do this, but this is always an option.
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
want to have a different separator.
And all this is doing, again, this is manipulating the arrays, using JavaScript.
So this is an array method where we can join the array together, turn it into a string, and we can
specify what we want as the separator between the items that were contained within the array.
So now we've got the number of emails that were found.
We've got the length and we've also got them as unique values are being returned and we're also changing
and updating the joiner.
So go ahead and add this into your application.
Try it for yourself, have some fun with it, experiment with it.
And next, we're going to do a quick code review of our email extractor.
So it's coming up next.
So go ahead and add this into your project, the ability to get the unique emails as well as to change
the separator for the emails that are being output for the user.