{"id":18699,"date":"2020-06-30T11:44:32","date_gmt":"2020-06-30T18:44:32","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=18699"},"modified":"2023-12-01T03:36:53","modified_gmt":"2023-12-01T11:36:53","slug":"javascript-map","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-map\/","title":{"rendered":"Map JavaScript: A Guide to the .map() Method"},"content":{"rendered":"\n<p>Programmers like to reduce repetition in their code. The more you repeat your code, the less maintainable it is, and the slower your programs will run. That\u2019s the reason why there are various methods in JavaScript to iterate through datasets.<br><\/p>\n\n\n\n<p>One of these methods is called the <code>map()<\/code> method. This method loops through an existing array and performs a specific function on all items in that array.<br><\/p>\n\n\n\n<p>In this guide, we\u2019re going to talk about how to use the JavaScript <code>map()<\/code> function. We\u2019ll walk through three common examples of the <code>map()<\/code> function in action to help you get started.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is the map Function?<\/h2>\n\n\n\n<p>The JavaScript <code>map()<\/code> method calls a specific function on each item in an array. The result of this function is then moved into its own array.<br><\/p>\n\n\n\n<p>For instance, suppose you want to multiply every item in an array by two. You could do so by creating a function that multiplies every array item by two, and moving that function into a <code>map()<\/code> method.<br><\/p>\n\n\n\n<p>The syntax of the <code>map()<\/code> function is:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const newArray = oldArray.map(function, thisValue);<\/pre><\/div>\n\n\n\n<p><code>function<\/code> is the callback function that will be run on each element in the array. To learn more about functions, you can read our ultimate guide to JavaScript functions. <code>thisValue<\/code> is the default value that will be stored in the <code>this<\/code> variable in the function. By default, this is undefined.<br><\/p>\n\n\n\n<p>The map method creates a new array based on the results of the callback function.<br><\/p>\n\n\n\n<p>The <code>map()<\/code> method has a number of uses. The most common is to call a function on a list of array elements. An example of this would be multiplying every number in a list of numbers, or finding the length of each string in a list of strings.<br><\/p>\n\n\n\n<p>You\u2019ll also find the function used to render lists in JavaScript libraries such as React or Vue.js.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Calling a Function with Map<\/h2>\n\n\n\n<p>The <code>map()<\/code> method allows you to perform a repetitive task on every item in a list, which makes it useful in a number of cases.<br><\/p>\n\n\n\n<p>Let\u2019s say that you own a cookie store and you are going to raise the prices of each cookie by 5%. Rather than calculating all of the new prices individually, you could use the <code>map()<\/code> method.<br><\/p>\n\n\n\n<p>Here\u2019s the code you would use:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>const cookiePrices = [1.50, 1.75, 1.60, 2.00, 2.05, 1.45];\nconst newCookiePrices = cookiePrices.map(cookie =&gt; {\n\tvar price = cookie * 1.05;\n\treturn price.toFixed(2);\n});\nconsole.log(newCookiePrices);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"1.58\", \"1.84\", \"1.68\", \"2.10\", \"2.15\", \"1.52\"]<\/pre><\/div>\n\n\n\n<p>In this example, we\u2019ve increased the price of every cookie by 5%. First, we declared a list of cookie prices in the variable \u201ccookiePrices\u201d. Then, we used the <code>map()<\/code> method with a function that calculates a 5% price increase for each cookie.<br><\/p>\n\n\n\n<p>\u201ccookie * 1.05\u201d calculated the percentage increase, then we returned that increase, rounded to the nearest two decimal places. Finally, we printed the new array to the console using the <code>console.log()<\/code> method.<br><\/p>\n\n\n\n<p>We could also move our function into its own function to make our code more readable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>function calculateIncrease(cookie) {\n\tvar price = cookie * 1.05;\n\treturn price.toFixed(2);\n}\nconst cookiePrices = [1.50, 1.75, 1.60, 2.00, 2.05, 1.45];\nconst newCookiePrices = cookiePrices.map(calculateIncrease);\nconsole.log(newCookiePrices);<\/pre><\/div>\n\n\n\n<p>Our code returns the same values from earlier, but is more readable:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"1.58\", \"1.84\", \"1.68\", \"2.10\", \"2.15\", \"1.52\"]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Change Items in an Array<\/h2>\n\n\n\n<p>The <code>map()<\/code> method is often used to change the items in an array. Let\u2019s suppose that our cookie shop is building a loyalty program for its customers. Every cookie you purchase earns you 10 points, and if you earn 100 points, you will earn a free cookie.<br><\/p>\n\n\n\n<p>The following program would allow us to accomplish this task:<br><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var customers = [\n\t{ name: \"Hannah Geoffrey\", cookiesPurchased: 2 },\n\t{ name: \"Peter Clarkson\", cookiesPurchased: 3 },\n\t{ name: \"Steven Hanson\", cookiesPurchased: 7 }\n]\nfunction calculateLoyaltyPoints(customer) {\n\tvar newCustomer = {\n\t\tname: customer.name,\n\t\tcookiesPurchased: customer.cookiesPurchased,\n\t\tpoints: customer.cookiesPurchased * 10\n\t}\n\treturn newCustomer;\n}\nvar customersWithPoints = customers.map(calculateLoyaltyPoints);\nconsole.log(customersWithPoints);<\/pre><\/div>\n\n\n\n<p>Our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[{ cookiesPurchased: 2, name: \"Hannah Geoffrey\", points: 20 }, { cookiesPurchased: 3, name: \"Peter Clarkson\", points: 30 }, { cookiesPurchased: 7, name: \"Steven Hanson\", points: 70 }]<\/pre><\/div>\n\n\n\n<p>In this example, we\u2019ve calculated the total number of points each customer should be awarded based on how many cookies they have purchased.<br><\/p>\n\n\n\n<p>First, we declared an array of objects called \u201ccustomers\u201d. This list stores the names of our customers and how many cookies they have purchased using key:value pairs.<br><\/p>\n\n\n\n<p>Then, we declared a function called <code>calculateLoyaltyPoints()<\/code>. This function adds a new item to each customer item called \u201cpoints\u201d which is calculated by multiplying the number of cookies each customer has purchased by 10.<br><\/p>\n\n\n\n<p>We use the <code>map()<\/code> method to iterate through our list of customers and apply our <code>calculateLoyaltyPoints()<\/code> function. Finally, we print out the revised list of customers. This list now reflects our \u201cpoints\u201d value we added to each customer\u2019s entry.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Render a List Using a Library<\/h2>\n\n\n\n<p>The <code>map()<\/code> method is commonly used in JavaScript libraries like React. The purpose of this method is to render the items in a list. Let\u2019s walk through an example of <code>map()<\/code> in React.<br><\/p>\n\n\n\n<p>Suppose we want to show a list of the cookies our store sells on our website. We could do so using this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>import React from \"react\";\nimport ReactDOM from \"react-dom\";\nvar cookies = [\"Raspberry Chocolate Chip\", \"White Chocolate Chip\", \"Oat\", \"Milk Chocolate Chip\"];\nconst CookieList = () =&gt; (\n\t&lt;div&gt;\n\t\t&lt;ul&gt;{cookies.map((cookie, i) =&gt; \n\t\t\t&lt;li key={i}&gt;{cookie}&lt;\/li&gt;\n\t\t       )}\n\t\t&lt;\/ul&gt;\n\t&lt;\/div&gt;\n);\nconst root = document.getElementById(\"root\");\nReactDOM.render(&lt;CookieList \/&gt;, root);<\/pre><\/div>\n\n\n\n<p>This code creates a component in React which renders a list. Each list item is contained within a &lt;li&gt; tag which is rendered using <code>map()<\/code>. <code>map()<\/code> creates an individual &lt;li&gt; tag for each item in the list, and the \u201ci\u201d variable assigns each list item a unique key.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Map vs. Iterator Methods<\/h2>\n\n\n\n<p>Map is an example of an iterator method in JavaScript. These methods allow you to loop through all the items in a list and perform some action.<br><\/p>\n\n\n\n<p>When you\u2019re deciding to use the <code>map()<\/code> function, it\u2019s good practice to first ask whether another iterator method would be better. This will ensure that you choose the right tool for the job.<br><\/p>\n\n\n\n<p>Here are the other iterator methods that exist in JavaScript:<br><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/careerkarma.com\/blog\/javascript-filter-reduce\/\"><strong>reduce()<\/strong><\/a>: The reduce method allows you to reduce an array to a single value. This method is best if you want to do something like adding up all the items in an array.<\/li>\n\n\n\n<li><a href=\"https:\/\/careerkarma.com\/blog\/javascript-filter-reduce\/\"><strong>filter()<\/strong><\/a>: Filter allows you to remove items from a list that do not meet particular criteria.<\/li>\n\n\n\n<li><a href=\"https:\/\/careerkarma.com\/blog\/javascript-foreach-loop\/\"><strong>forEach()<\/strong><\/a>: forEach() runs a function on every item in a list. forEach() is similar to a for loop because it allows you to loop over an array and perform a task on each item.<\/li>\n<\/ul>\n\n\n\n<p>You may be thinking to yourself, \u201cmap sounds really similar to the <code>forEach()<\/code> method. Are they the same?\u201d That\u2019s a good question. There is a subtle difference between these two methods.<br><\/p>\n\n\n\n<p>The <code>map()<\/code> function iterates over a list, changes each item in the list and returns a new list. The <code>forEach()<\/code> function, on the other hand, iterates over a list and, as a side effect, applies some operation to the list.<br><\/p>\n\n\n\n<p>The <code>map()<\/code> function is best used if you need to call a function on every item in a list, declare a list component in a framework like React, or change the content of a list.<\/p>\n\n\n\n<iframe loading=\"lazy\" frameborder=\"0\" width=\"100%\" height=\"400px\" src=\"https:\/\/repl.it\/@careerkarma\/JavaScript-Map?lite=true\"><\/iframe>\n<br>\n<br>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The <code>map()<\/code> method is useful for performing repetitive tasks multiple times. It\u2019s also useful for declaring components in React such as lists.<br><\/p>\n\n\n\n<p>In this tutorial, we analyzed three main uses of the <code>map()<\/code> method. Now you\u2019re ready to start using the JavaScript <code>map()<\/code> method like an expert developer!<\/p>\n","protected":false},"excerpt":{"rendered":"Programmers like to reduce repetition in their code. The more you repeat your code, the less maintainable it is, and the slower your programs will run. That\u2019s the reason why there are various methods in JavaScript to iterate through datasets. One of these methods is called the map() method. This method loops through an existing&hellip;","protected":false},"author":240,"featured_media":18700,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-18699","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.4 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Map JavaScript: A Guide to the .map() Method | Career Karma<\/title>\n<meta name=\"description\" content=\"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-map\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Map JavaScript: A Guide to the .map() Method\" \/>\n<meta property=\"og:description\" content=\"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-map\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-30T18:44:32+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:36:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Map JavaScript: A Guide to the .map() Method\",\"datePublished\":\"2020-06-30T18:44:32+00:00\",\"dateModified\":\"2023-12-01T11:36:53+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/\"},\"wordCount\":1083,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/bharat-patil-Vl6nLPF67rg-unsplash.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/\",\"name\":\"Map JavaScript: A Guide to the .map() Method | Career Karma\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/bharat-patil-Vl6nLPF67rg-unsplash.jpg\",\"datePublished\":\"2020-06-30T18:44:32+00:00\",\"dateModified\":\"2023-12-01T11:36:53+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#primaryimage\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/bharat-patil-Vl6nLPF67rg-unsplash.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/bharat-patil-Vl6nLPF67rg-unsplash.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript-map\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/javascript\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Map JavaScript: A Guide to the .map() Method\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/#\\\/schema\\\/person\\\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/01\\\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\\\/\\\/careerkarma.com\\\/blog\\\/author\\\/jamesgallagher\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Map JavaScript: A Guide to the .map() Method | Career Karma","description":"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-map\/","og_locale":"en_US","og_type":"article","og_title":"Map JavaScript: A Guide to the .map() Method","og_description":"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-map\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-06-30T18:44:32+00:00","article_modified_time":"2023-12-01T11:36:53+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Map JavaScript: A Guide to the .map() Method","datePublished":"2020-06-30T18:44:32+00:00","dateModified":"2023-12-01T11:36:53+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/"},"wordCount":1083,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-map\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/","url":"https:\/\/careerkarma.com\/blog\/javascript-map\/","name":"Map JavaScript: A Guide to the .map() Method | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg","datePublished":"2020-06-30T18:44:32+00:00","dateModified":"2023-12-01T11:36:53+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The JavaScript map() method is used to iterate through items in an array and execute a function on those items. On Career Karma, learn how to use the map() method.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-map\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/06\/bharat-patil-Vl6nLPF67rg-unsplash.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-map\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"Map JavaScript: A Guide to the .map() Method"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18699","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=18699"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/18699\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/18700"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=18699"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=18699"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=18699"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}