25 super useful methods in JavaScript
If you have just started learning JavaScript, you might have felt exhausted by seeing these 25 super useful methods in javascript. If you are simply going through those methods without knowing their use cases, it’s going to be tough for you later.
Let’s learn use cases.
Table of Contents.
❒ Array.prototype’s:-
- forEach()
- map()
- reduce()
- every()
- filter()
- find()
- slice()
- splice()
- push()
- pop()
- shift()
- unshift()
- indexOf()
- findIndex()
- sort()
❒ String.prototype’s:-
- toLowerCase()
- toUpperCase()
- substring()
- indexOf()
- charAt()
- trim()
❒ Math’s
- floor()
- random()
❒ Global
- setTimeout()
- setInterval()
#1: Array.prototype.forEach()
- To iterate through each element in the array
- Perform a task on each element
Not suitable if task is supposed to return some value.
✩✩ forEach() is also available in Set.prototype and Map.prototype
#2: Array.prototype. map()
- To iterate through each element in the array
- Perform a task on each element that returns a value
- Returns a new array with all returned values
Not suitable if task doesn’t return any value
#3: Array.prototype.reduce()
- To iterate through each element in the array
- Perform a task on each element that accumulates the previously returned value with the current element to return a new value
❍ Example
- Sum of all items
- Max of all items
This is a useful post for finding broken links within the website, what about links pointing outwards that are broken? I can use a free web service but wondered if this was possible.
Great tool! I am using a redirect plugin to send all my 404’s to my home page but I think it’s slacking sometimes. I noticed that some other sites have taken over my 404’s somehow.