More on ES6 part 4
COURSES CODE PLAYGROUND DISCUSS TOP LEARNERS 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: [4, 5, 1, 8, 2, 0].filter(function (x) { return x > 3; })[0]; Try It Yourself The new syntax is cleaner and more robust: [4, 5, 1, 8, 2, 0]. find (x => x > 3); Try It Yourself You can also get the index of the item above by using the findIndex() method : [4, 5, 1, 8, 2, 0]. findIndex (x => x > 3); Try It Yourself Repeating Strings Before ES6 the following syntax was the correct way to repeat a string multiple times: console.log(Array(3 + 1).join("foo")); // foofoofoo Try It Yourself With the new syntax, it becomes: console.log("foo". ...