More on ES6 part 4

More on ES6
216
4/4













Built-in Methods
ES6 also introduced new built-in methods to make several tasks easier. Here we will cover the most common ones.
Array Element Finding
The legacy way to find the first element of an array by its value and a rule was the following:
The new syntax is cleaner and more robust:
You can also get the index of the item above by using the findIndex() method:
Repeating Strings
Before ES6 the following syntax was the correct way to repeat a string multiple times:
With the new syntax, it becomes:
Searching Strings
Before ES6 we only used the indexOf() method to find the position of the text in the string. For example:
ES6 has replaced this with a version that has cleaner and more simplified syntax:
It is always a good practice to refactor your code with the new syntax to learn new things and make your code more understandable.
Comments
Post a Comment