Some awesome js tricks you should know about

is_ellie

Ellie

Posted on February 15, 2021

Some awesome js tricks you should know about

When it comes to adding all the numbers in an array, most people would think of the 'for loop' to traverse all the numbers, but other than that, do you know you can also use array.forEach() and array.reduce()to do so? Let's take an example here!

(1) array.forEach()
Alt Text

(2) array.reduce()
Alt Text

There're also lots of array tricks you may not know about, take a look at the examples below:

(3) use array.reverse() to reverse a string:

Alt Text

(4) repeat certain string for multiple times

Alt Text

We all know that spread operator can be used to split an array into a pseudo array,but it can also used to copy an object in react project! Look at the example below:

(5)use spread operator to copy an object in class component.

...To be continued

💖 💪 🙅 🚩
is_ellie
Ellie

Posted on February 15, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related