Welcome back.
Today, we're going to learn about Eastend new features, and it's called ECMAScript 2019.
How cool is this.
So when you consider where we were at the beginning with the is five now we are hearing learning about
Eastend.
So ladies and gentlemen, this is a huge success, huge improvement from where we were at the beginning.
Every year they release updates with new features and that is making our lives as a developers more
and much easier.
Why?
Because we need to we don't need to go back through what we have learned before.
We have the knowledge from the past and we can upgrade that knowledge with the new features.
Now, this is a cool part.
So two things will happen here.
Either they will update an old feature or a completely new feature in every incremental update to do
right now.
Today, we have a couple of important matters that I want to touch on.
The first one is flat matter.
The second one is flat map, dream, start stream and therefore the strings.
And here their methods in try and catch block.
So there is an update of that one, the way we are writing it.
So it's not huge update, but it's worth mentioning.
Okay, now the first one flat method now flat method.
We can use it on eraser.
OK, so let's write here something real quick so you can open any file or you can grab this year selector.
I will put it there for you guys right now.
So let's write something we haven't done before.
So let's write an array.
So const array here that will contain five numbers from one until five.
OK, so we haven't done this before, right?
Got that part.
I'm just joking.
So that is my sense of humor.
OK, so we have done this one multiple times.
Now, I can use the method here on top of this array and I will see a red dot flat.
Let's see what's happening.
I'm just going to copy this, the entire thing.
I'm going back to the the browser.
Go back to the console base that they're here enter.
And while I bring us the same same array back and why we are learning this method then.
Right.
So you going to ask me, OK, why do we need this?
So imagine if you have a mystery inside our array.
So this will be the perfect time for us to see an example with nested arrays.
OK, now move on.
I am going to make this country one and I will just say one, two.
And actually I'm going to put a mystery between two and three.
I mean, for two and three, then I'm going to leave four alone and I'm just going to go back with the
five and I'm going to add one more five and six here.
So one more element.
Each side.
Right.
OK.
The array, one that flat.
Remember, if I can write it, that will be great.
Now remember that you need to specify every one because we need to flip this one now.
Delete that one based on their hit enter.
And what do you see at the moment?
Wow.
We have one single tree, no nesting inside and that is just flat.
OK, so how cool is this?
Easy.
Now let's add another level of nesting and let's create a new area actually in.
So that will be a new example.
I'm just going to copy it here.
I'm going to type it.
So it's going to be a RETO here.
And let's add another level here, and I'm going to wrap this six actually to another level.
Nice.
And Oradea, two flat.
Copy it.
This one pasted back enter, you can use anything, actually, you can use Google Chrome, it's easier
there.
Now look what's happening.
I do have the array back, but this part, it's confusing right now.
I have the array now have another array here.
This array will have a one only one element called six.
Right.
So why is this happening now?
OK, let me explain.
Now, the interesting aspect of this flat method is that you can just specify how many levels we want
to be flat in.
The default is level one.
And here we don't passing anything.
So we don't if you don't pass any parameters here, like one, two or three, whatever it is, it's
going to automatically know, OK, this is level one and I'm going to flatten the entire rate to level
one.
Right.
Well, we can go crazy on this and we can just put it at level two here.
Let me just change it here and now.
You need to delete it.
Also refresh and based it back.
And voila, we have the entire array of six elements flatten and we have two levels inside.
Nothing.
Well, this was the first level.
This is the second level.
But inside we have the third level.
So that is how we can flatten this one.
OK, let me give you a crazy example here.
Just bear with me.
So I've copied from another file.
I'm going to put it here.
So what is this?
OK, we do have an array with animals, right?
We we have the sneak leyser squit.
I don't know what is this.
And yeah, we do have the dolphin fish or maybe Shakya this one.
Right.
We have the T rex here, the Dragon, Reino and Unicorn.
How cool is this.
But look at what what's happening here.
This is nesting one level, one level now three levels here or more to levels you can put more levels.
So how are you going to fix this now?
What you want to do is actually to release all the animals from this cage.
OK, I will give you like 50 seconds or a minute.
Think about it and let me know the answer, OK?
I don't ready.
So there are multiple ways and I'm going to show you the most easiest one.
So if you were like me, lazy, no, you can just go here and see animals not flat and just put it here.
Twenty crazy big.
No, I know there are not many levels inside, so let's copy paste it back here.
Hit enter and voila.
We do have that array completely flattened.
Right.
We don't have to think about it.
Nice.
There is other way that I will probably let you know but.
And not, not at this stage.
Right.
OK, let's move on.
So we stick to this flat to too much, but there are a couple more instances we can use.
Another scenario is that when flatmate and is working, when we have a data that is not consistent,
OK, let's create const data here and inside this data.
This will be an array, right?
I will have data of names in here.
I haven't any time here.
I use these names a lot in here.
I will have like some gibberish.
Nothing go Jason.
And here we have empty one.
The last one will be Chuck Norris.
You know this guy.
It's a legend.
Please check it out if you don't know it.
So data that's flat right now.
Let's see what's happening here.
So I have data that is not consistent here.
I have these empty things.
I have these three empty.
Now, this is not so look, this in the empty street is not same.
When I was first doing it, I was thinking, OK, maybe it's going to consider it as the same, but
it's not OK.
Hit enter.
Very good.
So I have any time to go.
Jason, check Chuck Norris and I have these empty still there, but that's not a problem.
I don't have the, the empty spaces here.
Nice.
So that will clean our data in data and we can use that really fast.
Now the next feature is called Flatmate.
OK, no flat map allows us to use the flat function and a map method on the array, so I'm going to
use the animals here array.
Let's create here const animal released.
Now they're in a cage locked up.
They can't go out.
They can't eat the squid here.
They can't eat the lizards or the the snake will not be able to eat any of it.
Right.
Or the rhino.
Same goes.
So I want a function that will do something crazy.
It will release all of them.
Right.
OK, so for that I can do the looping and I can do animals.
I should pass the equal sign there.
So animals grabbing this rate, putting the flat map, that's this is a new method right in here.
I'm going to pass the animal and I will say animal.
That's a current element that I'm looking through.
Right.
You can put any name you want and I will say animal plus three.
Now, what will happen?
This, you know.
OK, let's test it out, because I was thinking that you should know this bar, so I'm going to copy
this one.
I'm going to put it out here.
I'm going to paste it and hit enter.
Now go back to the animals released.
And here it is, the one they were together before.
I mean, this one, they're free now.
Right.
But not everything is free.
So you can see that here.
The snakes and this the snake is not free.
Only this one.
This guy's free.
This one is free.
This one is free and the fish free.
So that is go for the both of them.
Right.
So you can know here, it's adding only free to only one level, not after that.
So not every animal will be free from this prison cell.
Go now.
That's enough for this map method.
You can use it for more meaningful ways.
Now let's talk about dreams start and end.
And this is actually on string's.
Let's ride const username here, and I will see here a couple of empty spaces and I will say Rick here,
right consed last name.
OK, maybe we should make it like this nice so username in the last name, I do have them both, but
I am going to think here we can do something else.
I can add the two methods in one go no here.
Username and last name.
The user may have empty spaces in front in the last name has empty spaces after that.
So the quickest and easiest way to use a method is we can do it.
So the cost control along actually it will save me.
Thought it will save me time to write it here.
Right.
Just going to close this one.
Close that one now comes a lot.
I'm going to say username that so I can use here trem start.
Why.
Because I know, I know that I have empty spaces in front of this here.
I'm going to copy it here, I'm going to pass it back and I'm going to say last name, Treme and OK
now let's go there based back hit enter.
Nice.
So you can see that I don't have any empty spaces, I don't have spaces in the end.
So the Treme start will Treme, all these pieces that are trailing before and and the last name Will
Treme actually Treme and Will Treme.
All of these spaces.
They were here.
Right.
So you can do comes a lot actually you can do a lot here on the username in here it is.
See how many empty spaces we have before you can do the same thing for the last three
nights.
So actually you can't see it, but it's there like this when you did.
Oh, OK.
That is pretty much quick review of the feature stream start and stream.
And now another feature is from entries I always mix it up with from entries for entries, but it's
from entries.
So it will transform a list of key value pairs back to an object, not an array, but to an object.
So let's do a quick sample here.
No, I'm going to create here a username array, right.
So const user names in these array will have here, Andy and I will say, OK, let's give it the last
name.
Murray is a tennis player, by the way.
I don't like it, but I don't know his name is there in my mind all time to time party cuz I like this
guy forty five and I'm not sure how old is he now.
I have the Morgan.
Freeman, I hope I spell his last name right, 70 to maybe he's 75.
I'm no good.
Now look at this array.
It's pretty much unusable.
So what we can do about it.
So it will be real nice if we have the name and the age associated together combined.
And for that reason, we do have the object out from entries, right?
No object.
Not from.
Entries
in here.
I'm going to pass the user names, not user name user names, right?
Plural.
OK, let's copy this one based on back there, enter.
Well, we do have an object, Andy, that is associated with t h so this is super, super powerful.
One of the best features for this section.
So I have an array that's completely unusable, so we can't do much about it.
But here I do have with Object of Promontories each returning us an object where the name is associated
with the H and that is pretty much powerful.
So.
This is something very special because it links to a feature that I haven't done it before, and that
feature was released in the USA.
Cool.
Now that feature is totally opposite of this one.
And this was the place that I was thinking that it's best to say it now to object.
I'm just going to create here.
Const OBJ stands for object end user names.
OK, I am going to pass the entire area here,
I'm just going to copy paste it back.
So username is one.
Let's do it like this.
Now what I can do here is I can do object dot from entry's and I will say object.
So it's pretty much the same as this one.
But let's do the other one object the entries.
In our powers, the object again, no, I've done this because I, I will have a problem if I run the
same one here.
Now let's hit it.
Enter.
So the first one, actually, the last one will return me on the array.
So if I copy this one, refresh.
Delete that one.
Remove it this heat enter.
So I do have the object now, but the entrance is totally opposite it, return us from the object and
shift us back to the Narey.
Look at this.
So I have a rate of two elements inside and its name and the Murray.
But the same goes for this.
Same goes for this.
Now, object entries is totally opposite from Promontories.
This is turning the array to an object.
This is turning back the object on the right.
Cool in a problem is the last feature will be about trying to catch one.
Now try and catch right.
Remember here we passing the error all the time and here we counseling like the error.
And here we can pass the actual error now in a trap like we always put the code that we want to be executed,
right.
And if there is an error, we catch the error with the with this one.
Now, here I'm going to say Morgan.
Plus, let's give a space for your free man.
OK, now I shouldn't get any error if I run in here, delete this one pasted back and here it is.
I do have the Morgan Freeman.
Right.
So it's concatenating these two strings.
I don't have an error in here.
I do have I'm the error that it's from there.
OK, so let's throw an error here and see what's happening.
Remember that we can throw an error like this.
OK, now I do have the error is there putting it out right this one, plus I have the function error.
What's what's wrong with it right now in yes.
Ten or twenty 19.
There's something more easier.
We don't have to specify this parameter here or this argument that we are passing to an error.
Right.
It's still going to catch us the error.
So that is pretty much all about trying to catch.
I'm just going to refresh here.
Here it is, still catching the error.
We don't have to specify that error.
Right.
If we actually remove the throw and here it is, is going to execute what we have in the trial.
Nice.
So, ladies and gentlemen, these are the features that were the most famous for, yes.
19 or sorry, eastern 2019.
Now, you know all of it.
Let's recap what we have done.
Flat metal on a flat map here.
We can specify an argument how many levels we want to start treatment to a string and try and catch
Bluck.
Nice.
It also I haven't done it here, but it should be like this.
It's from entries, right?
The last one.
See, I've got about it.
OK, I'm just going to do it here and this will be number six.
Nice.
So that is pretty much it.
And also we have learned the opposite of this one and that is the entries only that will turn that will
convert the object back to an array sticker.
And I will see you in the next one.