By default sort function will sort the array alphabetic, so if you want to sort the array according to numeric value, pass in a callback function that compare two numbers.
[10, 2, 20, 5].sort(function (a, b) { return a - b; })isArray method is used to check whether the type of a variable is an array.
The filter(callback) method created a new array with elements that pass the callback function passed in.
var array = [1, 2, 3, 4] var newArray = array.filter(number => { return number > 2; }) console.log(array) // [1, 2, 3, 4] console.log(newArray) // [3, 4]The forEach(callback) method executes a provided function once for each element. The method implements iterator pattern. There is no way to stop or break a forEach() loop other than by throwing an exception. If you need such behavior, the forEach() method is the wrong tool. Use a plain loop instead.