1. How To Check Multiple Conditions?
Normally, we check more than one condition like:
For code fast and better way we check multiple condition using includes() or indexOf():
2. Easy Way To Convert An Object To An Array
3. How To Redirect a Web Page In Js?
4. Why Splice() Is Better Than Delete To Remove Element From Array?
Splice() remove element completely from the array.
Delete replace element with empty instead of removing it from Array. Delete should use to remove properties of Object
5. How to convert Number To String And String To Number Without Using Any Function?
Normally, to convert Number to String, we use toString():
To convert String to Number, we use Number():
But to code fast we can convert number to string without function:
To convert String to Number without function:
6. What Is Self-Invoking Function?
While we use a self-invoking function in script we don’t need to call, it runs automatically when page loads or parent function is called.
It’s good practice to use a self-invoking function rather than a normal function.
We just need to wrap functions with parenthesis.
7. How Can We Reduce The Complexity Of A For Loop With Iterators?
To reduce code complexity while we are working with iterators, we can use for…of loop instead of normal for loop.
While we use for .. of loop we don’t need to pay attention to length of built-in iterators like array, object, etc.
8. Which Is The Easy Way To Merge Two Arrays?
To merge two arrays simply use comma operator( , ).
By using this you can insert one array element into another one.
9. How To Easily Truncate Or Empty An Array?
If you know the original length of the array then you can easily truncate the array by re-define it’s length.
You can also use slice() to remove elements, it works even faster.
10. How Can We Find Only Relevant Data From An Array/Object ?
IWe can find mandatory data from an array/object using filter().
Filter() tests each element of the array and returns a new array with the elements which pass the test.