Easy, Optimised and Powerful Javascript with these hacks!!

Easy, Optimised and Powerful Javascript with these hacks!!

Writing Javascript with basic logic is easy but building a highly efficient software product is no cake, You gotta use the best of the best practices while writing code and write highly efficient algorithms as well

Here are some Javascript hacks you can use to write certain cleaner and more efficient code.


1. Extract Unique Values from given entries

We can create a new array only with the unique values by using the Set object and the Spread operator.

Untitled-1.png


2. Use length to resize an array

We can overwrite the length property on an array and resize or empty it.

To empty the array make length property 0

Untitled-1 (4).png


3. Convert a Multidimensional array to 1 Dimensional array with spread operator

Untitled-1 (3).png


4. Convert string to number with just + operator

Note:- Only works with strings which are numbers

Untitled-1.jpg


5. Convert number to string using concatenation

Untitled-1 (6).png


6. Shuffle elements inside the array

Untitled-1 (5).png


I hope you liked it, I post daily Web Dev tricks and resources, Consider following me on Twitter @ehteshaxm

For Web Development Resources try my website Codetote