![]() reduce() method reduces the array into a single value by executing the reducer function. You can also accomplish the same thing with traditionally for loop, but you have to give a detailed instruction hence the code is much verbose: var countriesWithOver100Million = ĬountriesWithOver100Million.push(countries) Ĭonsole.log(countriesWithOver100Million) The. map() method, the syntax is as the following: var newArr = arr.map(function callback(element, index, array) map() method is used to create a new array from the existing one based on the expression we provide in the callback function, the callback function here is the first argument of this. ![]() map() method in JavaScript kind of work the same way. In math, for example, we have a function, we put a number 2 to this function and it will give us 4, and put 3 inside this function will give us the result of 6, for any positive number, the mapping process of this function gives us a doubled value of a number we put on. A higher-order function is a function receives another function as its argument, and a callback function is a function passed as an argument of another function, clear enough? The. When learning those 3 methods we easily stumble upon some concepts such as a higher-order function or callback function.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |