{"id":809,"date":"2018-10-01T00:56:17","date_gmt":"2018-10-01T00:56:17","guid":{"rendered":"https:\/\/blog.hassler.ec\/wp\/?p=809"},"modified":"2018-09-26T01:00:15","modified_gmt":"2018-09-26T01:00:15","slug":"these-javascript-methods-will-boost-your-skills-in-just-a-few-minutes","status":"publish","type":"post","link":"https:\/\/blog.hassler.ec\/wp\/2018\/10\/01\/these-javascript-methods-will-boost-your-skills-in-just-a-few-minutes\/","title":{"rendered":"These JavaScript methods will boost your skills in just a few\u00a0minutes"},"content":{"rendered":"<section class=\"section section--body section--first\">\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<figure id=\"6984\" class=\"graf graf--figure graf-after--h3\">\n<div class=\"aspectRatioPlaceholder\"><img decoding=\"async\" class=\"graf-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*H-25KB7EbSHjv70HXrdl6w.png\" alt=\"Bilderesultat for javascript\" data-image-id=\"1*H-25KB7EbSHjv70HXrdl6w.png\" \/><\/div>\n<\/figure>\n<p id=\"f1a4\" class=\"graf graf--p graf-after--figure\">Most of the applications we build today require some sort of data collection modification. Processing items in a collection is a common operation you will most likely encounter. Forget the conventional way of doing\u00a0<code class=\"markup--code markup--p-code\">for-loop<\/code>\u00a0like\u00a0<code class=\"markup--code markup--p-code\">(let i=0; i &lt; value.length; i++ )<\/code>.<\/p>\n<blockquote id=\"f971\" class=\"graf graf--blockquote graf-after--p\"><p>Quick heads-up, using\u00a0<code class=\"markup--code markup--blockquote-code\">const<\/code>\u00a0in\u00a0<code class=\"markup--code markup--blockquote-code\">for-loop<\/code>\u00a0will give you an error. Reason why is because it re-declares the value during each execution hence\u00a0<code class=\"markup--code markup--blockquote-code\">i<\/code>\u00a0is modified by\u00a0<code class=\"markup--code markup--blockquote-code\">i++<\/code>. So whenever you think of either using\u00a0<code class=\"markup--code markup--blockquote-code\">const<\/code>\u00a0or\u00a0<code class=\"markup--code markup--blockquote-code\">let<\/code>, ask yourself\u200a\u2014\u200aWill this value be re-declared? If the answer is\u00a0<strong class=\"markup--strong markup--blockquote-strong\">yes<\/strong>, go for\u00a0<code class=\"markup--code markup--blockquote-code\">let<\/code>\u00a0, and if\u00a0<strong class=\"markup--strong markup--blockquote-strong\">no<\/strong>, go for\u00a0<code class=\"markup--code markup--blockquote-code\">const<\/code>.\u00a0<a class=\"markup--anchor markup--blockquote-anchor\" href=\"https:\/\/stackoverflow.com\/questions\/41067790\/why-does-const-work-in-some-for-loops-in-javascript\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/stackoverflow.com\/questions\/41067790\/why-does-const-work-in-some-for-loops-in-javascript\">More info<\/a>.<\/p><\/blockquote>\n<p id=\"19c0\" class=\"graf graf--p graf-after--blockquote\">Let\u2019s say you want to show list of products and categorize, filter, search, modify or update a collection. Or maybe you want to perform quick calculations such as sum, multiplication, and so forth. What is the optimal way to achieve this?<\/p>\n<p id=\"bcf2\" class=\"graf graf--p graf-after--p\">Maybe you don\u2019t like\u00a0<strong class=\"markup--strong markup--p-strong\">arrow functions<\/strong>, you don\u2019t want to spend too much time learning something new, or they\u2019re just not relevant for you. Don\u2019t worry, you are not alone. I\u2019ll show you how it is done in ES5 (functional deceleration) and ES6 (arrow functions).<\/p>\n<p id=\"e600\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Be aware:<\/strong>\u00a0Arrow functions and function declarations \/ expressions are not equivalent and cannot be\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/stackoverflow.com\/questions\/34361379\/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/stackoverflow.com\/questions\/34361379\/arrow-function-vs-function-declaration-expressions-are-they-equivalent-exch?utm_medium=organic&amp;utm_source=google_rich_qa&amp;utm_campaign=google_rich_qa\">replaced blindly<\/a>. Keep in mind that the\u00a0<code class=\"markup--code markup--p-code\">this<\/code>keyword works differently between the two.<\/p>\n<h4 id=\"ec29\" class=\"graf graf--h4 graf-after--p\">The methods we\u2019ll be looking\u00a0at:<\/h4>\n<ol class=\"postList\">\n<li id=\"4c53\" class=\"graf graf--li graf-after--h4\">Spread operator<\/li>\n<li id=\"c3d3\" class=\"graf graf--li graf-after--li\">for\u2026of iterator<\/li>\n<li id=\"83e6\" class=\"graf graf--li graf-after--li\">includes()<\/li>\n<li id=\"f033\" class=\"graf graf--li graf-after--li\">some()<\/li>\n<li id=\"3056\" class=\"graf graf--li graf-after--li\">every()<\/li>\n<li id=\"86a9\" class=\"graf graf--li graf-after--li\">filter()<\/li>\n<li id=\"0ee6\" class=\"graf graf--li graf-after--li\">map()<\/li>\n<li id=\"828c\" class=\"graf graf--li graf-after--li\">reduce()<\/li>\n<\/ol>\n<blockquote id=\"6b99\" class=\"graf graf--blockquote graf-after--li\"><p><span class=\"markup--quote markup--blockquote-quote is-other\" data-creator-ids=\"anon\">If you want to become a better web developer, start your own business, teach others, or improve your development skills, I\u2019ll be posting weekly tips and tricks on the latest web development languages.<\/span><\/p><\/blockquote>\n<h3 id=\"7e53\" class=\"graf graf--h3 graf-after--blockquote\">1. Spread\u00a0operator<\/h3>\n<p id=\"5a1d\" class=\"graf graf--p graf-after--h3\">The Spread Operator\u00a0<strong class=\"markup--strong markup--p-strong\">expands<\/strong>\u00a0an array into its elements. It can also be used for object literals.<\/p>\n<p id=\"b132\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"dacc\" class=\"graf graf--li graf-after--p\">It\u2019s a simple and fast way to show the items of an array<\/li>\n<li id=\"26ae\" class=\"graf graf--li graf-after--li\">It works for arrays and object literals<\/li>\n<li id=\"bad8\" class=\"graf graf--li graf-after--li\">It\u2019s a quick and intuitive way to pass arguments<\/li>\n<li id=\"107e\" class=\"graf graf--li graf-after--li\">It only requires three dots\u2026<\/li>\n<\/ul>\n<p id=\"fa3d\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you want to show a list of favorite foods without creating a loop function. Use a spread operator like this:<\/p>\n<figure id=\"a82c\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*NPgk0vqyWiXXkNDPMbxujA.png\" data-width=\"816\" data-height=\"217\" data-action=\"zoom\" data-action-value=\"1*NPgk0vqyWiXXkNDPMbxujA.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"17\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*NPgk0vqyWiXXkNDPMbxujA.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*NPgk0vqyWiXXkNDPMbxujA.png\" \/><\/div>\n<\/div>\n<\/figure>\n<h3 id=\"bc52\" class=\"graf graf--h3 graf-after--figure\">2. for\u2026of\u00a0iterator<\/h3>\n<p id=\"94c0\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">for...of<\/code>\u00a0statement loops\/iterates through the collection, and provides you the ability to modify specific items. It replaces the conventional way of doing a\u00a0<code class=\"markup--code markup--p-code\">for-loop<\/code>.<\/p>\n<p id=\"5d6e\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"e6e0\" class=\"graf graf--li graf-after--p\">It\u2019s a simple way to add or update an item<\/li>\n<li id=\"4346\" class=\"graf graf--li graf-after--li\">To perform calculations (sum, multiplication etc)<\/li>\n<li id=\"90ef\" class=\"graf graf--li graf-after--li\">When using conditional statements (if, while, switch, and so on)<\/li>\n<li id=\"43f9\" class=\"graf graf--li graf-after--li\">Leads to clean and readable code<\/li>\n<\/ul>\n<p id=\"e45e\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you have a toolbox, and you want to show all the tools inside it. The\u00a0<code class=\"markup--code markup--p-code\">for...of<\/code>\u00a0iterator makes it easy.<\/p>\n<figure id=\"e21d\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*kjQYvjeeHUuP8inZYqjJVg.png\" data-width=\"710\" data-height=\"327\" data-action=\"zoom\" data-action-value=\"1*kjQYvjeeHUuP8inZYqjJVg.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"32\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*kjQYvjeeHUuP8inZYqjJVg.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*kjQYvjeeHUuP8inZYqjJVg.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">for\u2026of operator<\/figcaption><\/figure>\n<h3 id=\"f37f\" class=\"graf graf--h3 graf-after--figure\">3. Includes() method<\/h3>\n<p id=\"e35e\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">includes()<\/code>\u00a0method is used to check if a specific string exists in a collection, and returns\u00a0<code class=\"markup--code markup--p-code\">true<\/code>\u00a0or\u00a0<code class=\"markup--code markup--p-code\">false<\/code>. Keep in mind that it is case sensitive: if the item inside the collection is\u00a0<code class=\"markup--code markup--p-code\">SCHOOL<\/code>, and you search for\u00a0<code class=\"markup--code markup--p-code\">school<\/code>, it will return\u00a0<code class=\"markup--code markup--p-code\">false<\/code>.<\/p>\n<p id=\"90fd\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"ed35\" class=\"graf graf--li graf-after--p\">To build simple search-functionality<\/li>\n<li id=\"54aa\" class=\"graf graf--li graf-after--li\">It\u2019s an intuitive approach to determine if a string exists<\/li>\n<li id=\"17f4\" class=\"graf graf--li graf-after--li\">It uses conditional statements to modify, filter, and so on<\/li>\n<li id=\"97ac\" class=\"graf graf--li graf-after--li\">Leads to readable code<\/li>\n<\/ul>\n<p id=\"c9dd\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say for whatever reason that you are not aware of what cars you have in your garage, and you need a system to check if the car you want exists or not.\u00a0<code class=\"markup--code markup--p-code\">includes()<\/code>to the rescue!<\/p>\n<figure id=\"911b\" class=\"graf graf--figure graf-after--p\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*m1InU7VDxdfpxMXuV2A1MA.png\" data-width=\"816\" data-height=\"261\" data-action=\"zoom\" data-action-value=\"1*m1InU7VDxdfpxMXuV2A1MA.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"22\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*m1InU7VDxdfpxMXuV2A1MA.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*m1InU7VDxdfpxMXuV2A1MA.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">includes() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<h3 id=\"24fb\" class=\"graf graf--h3 graf-after--figure\">4. Some()\u00a0method<\/h3>\n<p id=\"8bbe\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">some()<\/code>\u00a0method checks if some elements exists in an array, and returns\u00a0<code class=\"markup--code markup--p-code\">true<\/code>\u00a0or\u00a0<code class=\"markup--code markup--p-code\">false<\/code>. This is somewhat similar to the concept of the\u00a0<code class=\"markup--code markup--p-code\">includes()<\/code>method, except the argument is a function and not a string.<\/p>\n<p id=\"dabe\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"0ba6\" class=\"graf graf--li graf-after--p\">It makes sure\u00a0<strong class=\"markup--strong markup--li-strong\">some<\/strong>\u00a0item passes the test<\/li>\n<li id=\"03c2\" class=\"graf graf--li graf-after--li\">It performs conditional statements using functions<\/li>\n<li id=\"a1f0\" class=\"graf graf--li graf-after--li\">Make your code declarative<\/li>\n<li id=\"d0d1\" class=\"graf graf--li graf-after--li\">Some is good enough<\/li>\n<\/ul>\n<p id=\"4b53\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you are a club owner, and don\u2019t care who enters the club. But some are not allowed in, because they have been drinking too much (my creativity at its best). Check out the differences between ES5 and ES6 below:<\/p>\n<h4 id=\"ed52\" class=\"graf graf--h4 graf-after--p\">ES5:<\/h4>\n<figure id=\"2d85\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*-5YnlNy48wi0FHnIG3bXDg.png\" data-width=\"861\" data-height=\"306\" data-action=\"zoom\" data-action-value=\"1*-5YnlNy48wi0FHnIG3bXDg.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"25\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*-5YnlNy48wi0FHnIG3bXDg.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*-5YnlNy48wi0FHnIG3bXDg.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">some() method<\/figcaption><\/figure>\n<h4 id=\"d41e\" class=\"graf graf--h4 graf-after--figure\">ES6:<\/h4>\n<figure id=\"dd0c\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*pmaXrKpg5vI__WwztfATGg.png\" data-width=\"816\" data-height=\"239\" data-action=\"zoom\" data-action-value=\"1*pmaXrKpg5vI__WwztfATGg.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"20\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*pmaXrKpg5vI__WwztfATGg.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*pmaXrKpg5vI__WwztfATGg.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">some() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<h3 id=\"b1b6\" class=\"graf graf--h3 graf-after--figure\">5. Every()\u00a0method<\/h3>\n<p id=\"96dd\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">every()<\/code>\u00a0method loops through the array, checks every<strong class=\"markup--strong markup--p-strong\">\u00a0<\/strong>item, and returns\u00a0<code class=\"markup--code markup--p-code\">true<\/code>\u00a0or\u00a0<code class=\"markup--code markup--p-code\">false<\/code>. Same concept as\u00a0<code class=\"markup--code markup--p-code\">some()<\/code>. Except every item must satisfy the conditional statement, otherwise, it will return\u00a0<code class=\"markup--code markup--p-code\">false<\/code>.<\/p>\n<p id=\"7039\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"9859\" class=\"graf graf--li graf-after--p\">It makes sure\u00a0<strong class=\"markup--strong markup--li-strong\">every<\/strong>\u00a0item passes the test<\/li>\n<li id=\"6b52\" class=\"graf graf--li graf-after--li\">You can perform conditional statements using functions<\/li>\n<li id=\"4cf0\" class=\"graf graf--li graf-after--li\">Make your code declarative<\/li>\n<\/ul>\n<p id=\"1224\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>The last time you allowed\u00a0<code class=\"markup--code markup--p-code\">some()<\/code>\u00a0underage students to enter the club, someone reported this and the police caught you. This time you won\u2019t let that happen, and you\u2019ll make sure that\u00a0<strong class=\"markup--strong markup--p-strong\">everyone<\/strong>\u00a0passes the age limit with the\u00a0<code class=\"markup--code markup--p-code\">every()<\/code>operator.<\/p>\n<h4 id=\"aa21\" class=\"graf graf--h4 graf-after--p\">ES5<\/h4>\n<figure id=\"c1d0\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*DNQqzRJ_K01ognj3_c8HqQ.png\" data-width=\"861\" data-height=\"328\" data-action=\"zoom\" data-action-value=\"1*DNQqzRJ_K01ognj3_c8HqQ.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"27\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*DNQqzRJ_K01ognj3_c8HqQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*DNQqzRJ_K01ognj3_c8HqQ.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">every() method<\/figcaption><\/figure>\n<h4 id=\"26e2\" class=\"graf graf--h4 graf-after--figure\">ES6<\/h4>\n<figure id=\"edfa\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*avukLSBlIG1ycSzoHLMOYA.png\" data-width=\"816\" data-height=\"239\" data-action=\"zoom\" data-action-value=\"1*avukLSBlIG1ycSzoHLMOYA.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"20\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*avukLSBlIG1ycSzoHLMOYA.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*avukLSBlIG1ycSzoHLMOYA.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">every() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<h3 id=\"819b\" class=\"graf graf--h3 graf-after--figure\">6. Filter()\u00a0method<\/h3>\n<p id=\"09bb\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">filter()<\/code>\u00a0method creates a new array with all elements that pass the test.<\/p>\n<p id=\"8349\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"7c14\" class=\"graf graf--li graf-after--p\">So you can avoid changing the main array<\/li>\n<li id=\"215a\" class=\"graf graf--li graf-after--li\">It lets you filter out items you do not need<\/li>\n<li id=\"475b\" class=\"graf graf--li graf-after--li\">Gives you more readable code<\/li>\n<\/ul>\n<p id=\"1ae4\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you want to return only prices that are above or equal to 30. Filter out all those other prices\u2026<\/p>\n<h4 id=\"9f57\" class=\"graf graf--h4 graf-after--p\">ES5<\/h4>\n<figure id=\"a439\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*O9EhGZRxC1DWan0822fKvQ.png\" data-width=\"710\" data-height=\"271\" data-action=\"zoom\" data-action-value=\"1*O9EhGZRxC1DWan0822fKvQ.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"27\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*O9EhGZRxC1DWan0822fKvQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*O9EhGZRxC1DWan0822fKvQ.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">filter() method<\/figcaption><\/figure>\n<h4 id=\"3af3\" class=\"graf graf--h4 graf-after--figure\">ES6<\/h4>\n<figure id=\"67ea\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*1C22z5zvw_Gw_SiJnLuTig.png\" data-width=\"816\" data-height=\"239\" data-action=\"zoom\" data-action-value=\"1*1C22z5zvw_Gw_SiJnLuTig.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"20\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*1C22z5zvw_Gw_SiJnLuTig.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*1C22z5zvw_Gw_SiJnLuTig.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">filter() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<h3 id=\"ae96\" class=\"graf graf--h3 graf-after--figure\">7. Map()\u00a0method<\/h3>\n<p id=\"8c1b\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">map()<\/code>\u00a0method is similar to the\u00a0<code class=\"markup--code markup--p-code\">filter()<\/code>\u00a0method in terms of returning a new array. However, the only difference is that it is used to modify items.<\/p>\n<p id=\"2186\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"5f1f\" class=\"graf graf--li graf-after--p\">It lets you avoid making changes to the main array<\/li>\n<li id=\"37b4\" class=\"graf graf--li graf-after--li\">You can modify the items you want<\/li>\n<li id=\"6a42\" class=\"graf graf--li graf-after--li\">Gives you more readable code<\/li>\n<\/ul>\n<p id=\"1963\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you have a list of products with prices. Your manager needs a list to show the new prices after they have been taxed by 25%. The\u00a0<code class=\"markup--code markup--p-code\">map()<\/code>\u00a0method can help you out.<\/p>\n<h4 id=\"0262\" class=\"graf graf--h4 graf-after--p\">ES5<\/h4>\n<figure id=\"b0cf\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*iIOcN4rc6r-55YWrHQVNHw.png\" data-width=\"816\" data-height=\"306\" data-action=\"zoom\" data-action-value=\"1*iIOcN4rc6r-55YWrHQVNHw.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"27\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*iIOcN4rc6r-55YWrHQVNHw.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*iIOcN4rc6r-55YWrHQVNHw.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">map() method<\/figcaption><\/figure>\n<h4 id=\"3bac\" class=\"graf graf--h4 graf-after--figure\">ES6<\/h4>\n<figure id=\"4096\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*s2ePAwDuw-qJOju7WAm9Uw.png\" data-width=\"816\" data-height=\"217\" data-action=\"zoom\" data-action-value=\"1*s2ePAwDuw-qJOju7WAm9Uw.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"17\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*s2ePAwDuw-qJOju7WAm9Uw.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*s2ePAwDuw-qJOju7WAm9Uw.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">map() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<h3 id=\"a6d3\" class=\"graf graf--h3 graf-after--figure\">8. Reduce()\u00a0method<\/h3>\n<p id=\"bac3\" class=\"graf graf--p graf-after--h3\">The\u00a0<code class=\"markup--code markup--p-code\">reduce()<\/code>\u00a0method can be used to transform an array into something else, which could be an integer, an object, a chain of promises ( sequential execution of promises) etc. For practical reasons, a simple use case would be to sum a list of integers. In short, it \u201creduces\u201d the whole array into one value.<\/p>\n<p id=\"0f0f\" class=\"graf graf--p graf-after--p\"><strong class=\"markup--strong markup--p-strong\">Why should I use it?<\/strong><\/p>\n<ul class=\"postList\">\n<li id=\"ab2c\" class=\"graf graf--li graf-after--p\">Perform calculations<\/li>\n<li id=\"a892\" class=\"graf graf--li graf-after--li\">Calculate a value<\/li>\n<li id=\"6842\" class=\"graf graf--li graf-after--li\">Count duplicates<\/li>\n<li id=\"8e7a\" class=\"graf graf--li graf-after--li\">Group objects by property<\/li>\n<li id=\"c284\" class=\"graf graf--li graf-after--li\">Execute promises sequentially<\/li>\n<li id=\"e46b\" class=\"graf graf--li graf-after--li\">It\u2019s a quick way to perform calculations<\/li>\n<\/ul>\n<p id=\"1d9e\" class=\"graf graf--p graf-after--li\"><strong class=\"markup--strong markup--p-strong\">Example:<br \/>\n<\/strong>Let\u2019s say you want to find out your total expenses for a week. Use\u00a0<code class=\"markup--code markup--p-code\">reduce()<\/code>\u00a0to get that value.<\/p>\n<h4 id=\"3955\" class=\"graf graf--h4 graf-after--p\">ES5<\/h4>\n<figure id=\"a807\" class=\"graf graf--figure graf-after--h4\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*OX1oPjVVoPXfIsAqHD3TTQ.png\" data-width=\"710\" data-height=\"290\" data-action=\"zoom\" data-action-value=\"1*OX1oPjVVoPXfIsAqHD3TTQ.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"30\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*OX1oPjVVoPXfIsAqHD3TTQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*OX1oPjVVoPXfIsAqHD3TTQ.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">reduce() method<\/figcaption><\/figure>\n<h4 id=\"51c0\" class=\"graf graf--h4 graf-after--figure\">ES6<\/h4>\n<figure id=\"f169\" class=\"graf graf--figure graf-after--h4 graf--trailing\">\n<div class=\"aspectRatioPlaceholder is-locked\">\n<div class=\"aspectRatioPlaceholder-fill\"><\/div>\n<div class=\"progressiveMedia js-progressiveMedia graf-image is-canvasLoaded is-imageLoaded\" data-image-id=\"1*DGa7HZwy40o71B4_ICP6kQ.png\" data-width=\"710\" data-height=\"215\" data-action=\"zoom\" data-action-value=\"1*DGa7HZwy40o71B4_ICP6kQ.png\" data-scroll=\"native\"><canvas class=\"progressiveMedia-canvas js-progressiveMedia-canvas\" width=\"75\" height=\"22\"><\/canvas><img decoding=\"async\" class=\"progressiveMedia-image js-progressiveMedia-image\" src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*DGa7HZwy40o71B4_ICP6kQ.png\" data-src=\"https:\/\/cdn-images-1.medium.com\/max\/800\/1*DGa7HZwy40o71B4_ICP6kQ.png\" \/><\/div>\n<\/div><figcaption class=\"imageCaption\">reduce() method w\/ arrow\u00a0function<\/figcaption><\/figure>\n<\/div>\n<\/div>\n<\/section>\n<section class=\"section section--body section--last\">\n<div class=\"section-divider\">\n<hr class=\"section-divider\" \/>\n<\/div>\n<div class=\"section-content\">\n<div class=\"section-inner sectionLayout--insetColumn\">\n<p id=\"6553\" class=\"graf graf--p graf--leading\">You can find me on Medium where I publish every week. Or you can follow me on\u00a0<a class=\"markup--anchor markup--p-anchor\" href=\"http:\/\/twitter.com\/dleroari\" target=\"_blank\" rel=\"noopener\" data-href=\"http:\/\/twitter.com\/dleroari\">Twitter<\/a>, where I post relevant web development tips and tricks.<\/p>\n<p id=\"2e22\" class=\"graf graf--p graf-after--p graf--trailing\"><em class=\"markup--em markup--p-em\">P.S. If you enjoyed this article and want more like these, please clap \u2764 and share with friends, it\u2019s good karma.<\/em><\/p>\n<\/div>\n<\/div>\n<\/section>\n<p>&nbsp;<\/p>\n<p>Source:\u00a0<a href=\"https:\/\/medium.freecodecamp.org\/7-javascript-methods-that-will-boost-your-skills-in-less-than-8-minutes-4cc4c3dca03f\"><strong>https:\/\/medium.freecodecamp.org\/7-javascript-methods-that-will-boost-your-skills-in-less-than-8-minutes-4cc4c3dca03f<\/strong><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>Written by<\/p>\n<div class=\"u-tableCell\"><a class=\"link u-baseColor--link avatar\" dir=\"auto\" title=\"Go to the profile of Dler Ari\" href=\"https:\/\/medium.freecodecamp.org\/@dleroari?source=footer_card\" aria-label=\"Go to the profile of Dler Ari\" data-action-source=\"footer_card\" data-user-id=\"6b4a1cde263\" data-collection-slug=\"free-code-camp\"><img decoding=\"async\" class=\"avatar-image avatar-image--small alignleft\" src=\"https:\/\/cdn-images-1.medium.com\/fit\/c\/60\/60\/1*CpeIh0Wi0pyNvrwX0dAang.jpeg\" alt=\"Go to the profile of Dler Ari\" \/><\/a><\/div>\n<div class=\"u-tableCell u-verticalAlignMiddle u-breakWord u-paddingLeft15\">\n<h3 class=\"ui-h3 u-fontSize18 u-lineHeightTighter u-marginBottom4\"><a class=\"link link--primary u-accentColor--hoverTextNormal\" dir=\"auto\" title=\"Go to the profile of Dler Ari\" href=\"https:\/\/medium.freecodecamp.org\/@dleroari\" rel=\"author cc:attributionUrl\" aria-label=\"Go to the profile of Dler Ari\" data-user-id=\"6b4a1cde263\" data-collection-slug=\"free-code-camp\">Dler Ari<\/a><\/h3>\n<p class=\"ui-body u-fontSize14 u-lineHeightBaseSans u-textColorDark u-marginBottom4\">SW Engineer, Web Developer and a husband. Taking complex topics and simplifying them.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div class=\"u-tableCell \"><a class=\"link u-baseColor--link avatar avatar--roundedRectangle\" title=\"Go to freeCodeCamp.org\" href=\"https:\/\/medium.freecodecamp.org\/?source=footer_card\" aria-label=\"Go to freeCodeCamp.org\" data-action-source=\"footer_card\" data-collection-slug=\"free-code-camp\"><img decoding=\"async\" class=\"avatar-image u-size60x60 alignleft\" src=\"https:\/\/cdn-images-1.medium.com\/fit\/c\/60\/60\/1*MotlWcSa2n6FrOx3ul89kw.png\" alt=\"freeCodeCamp.org\" \/><\/a><\/div>\n<div class=\"u-tableCell u-verticalAlignMiddle u-breakWord u-paddingLeft15\">\n<h3 class=\"ui-h3 u-fontSize18 u-lineHeightTighter u-marginBottom4\"><a class=\"link link--primary u-accentColor--hoverTextNormal\" href=\"https:\/\/medium.freecodecamp.org\/?source=footer_card\" rel=\"collection\" data-action-source=\"footer_card\" data-collection-slug=\"free-code-camp\">freeCodeCamp.org<\/a><\/h3>\n<p class=\"ui-body u-fontSize14 u-lineHeightBaseSans u-textColorDark u-marginBottom4\">Stories worth reading about programming and technology from our open source community.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Most of the applications we build today require some sort of data collection modification. Processing items in a collection is [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":86,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[12,88,48,44,47],"tags":[],"class_list":["post-809","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-bloghassler-ec","category-design","category-front-end","category-javascript","category-medium"],"_links":{"self":[{"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/posts\/809","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/comments?post=809"}],"version-history":[{"count":1,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/posts\/809\/revisions"}],"predecessor-version":[{"id":810,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/posts\/809\/revisions\/810"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/media\/86"}],"wp:attachment":[{"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/media?parent=809"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/categories?post=809"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.hassler.ec\/wp\/wp-json\/wp\/v2\/tags?post=809"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}