{"id":561822,"date":"2019-07-08T06:28:22","date_gmt":"2019-07-08T13:28:22","guid":{"rendered":"https:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=561822"},"modified":"2020-01-29T01:40:29","modified_gmt":"2020-01-29T09:40:29","slug":"code-snippets-arcgis-api-javascript","status":"publish","type":"blog","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","title":{"rendered":"Useful code snippets for ArcGIS API for JavaScript"},"author":7011,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"_acf_changed":false,"_searchwp_excluded":""},"categories":[22941],"tags":[43161,549072,24921],"industry":[],"product":[36831,36601],"class_list":["post-561822","blog","type-blog","status-publish","format-standard","hentry","category-mapping","tag-developer","tag-esrirdzurich","tag-javascript","product-js-api-arcgis","product-developers"],"acf":{"short_description":"Discover how to use code snippets to speed up your ArcGIS API for JavaScript web app development.","flexible_content":[{"acf_fc_layout":"content","content":"<p class=\"graf graf--p\">If you\u2019re creating web applications with ArcGIS API for JavaScript then you probably ran into those situations where you couldn\u2019t remember how to set that <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-renderers-UniqueValueRenderer.html\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-renderers-UniqueValueRenderer.html\">UniqueValueRenderer<\/a>. So you went to the documentation, copy pasted the example code and then customized it for your data. In this blog post we want to show you a workflow where you make use of code snippets to avoid having to leave the editor and also to write less code (we created a plugin with code snippets for Visual Studio Code, but you can actually create your own code snippets for any other editor).<\/p>\n<p class=\"graf graf--p\">Another workflow where code snippets come in handy, is when debugging. Besides setting breakpoints and pausing on exceptions (we mainly use Google Chrome for debugging), you can also get access to the view, navigate the layers in your map, get the camera position in 3D or figure out when everything was loaded with just a few code snippets in the console.<\/p>\n<p class=\"graf graf--p\">So let\u2019s get started!<\/p>\n"},{"acf_fc_layout":"content","content":"<h2>Development code snippets<\/h2>\n<p class=\"graf graf--p\">These are the code snippets that you use during development, representing boilerplate code, a verbose syntax that you can never remember, or maybe just a simple syntax that you have to repeat over and over again in your code (ok, that might be subject to some refactoring if you have to repeat it that often\u2026).<\/p>\n<p class=\"graf graf--p\">So let me show you an example. Something I can never remember is the code for adding labels in 3D. Instead of having to memorize all the properties that I need to set on the <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-layers-support-LabelClass.html\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/developers.arcgis.com\/javascript\/latest\/api-reference\/esri-layers-support-LabelClass.html\">LabelClass<\/a> and then type them, I can just type a prefix like <code class=\"markup--code markup--p-code\">labeling3d<\/code>, press <code class=\"markup--code markup--p-code\">Tab<\/code> and the code snippet will show up with placeholders for my custom values:<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":561902,"id":561902,"title":"code snippets vscode","filename":"code-vscode.gif","filesize":964564,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\/code-vscode","alt":"code snippets vscode","author":"7011","description":"How to work with code snippets in Visual Studio Code.","caption":"How to work with code snippets in Visual Studio Code.","name":"code-vscode","status":"inherit","uploaded_to":561822,"date":"2019-07-08 12:30:39","modified":"2019-07-08 12:58:31","menu_order":0,"mime_type":"image\/gif","type":"image","subtype":"gif","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":1000,"height":696,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode-213x200.gif","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","medium-width":375,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","medium_large-width":768,"medium_large-height":535,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","large-width":1000,"large-height":696,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","1536x1536-width":1000,"1536x1536-height":696,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","2048x2048-width":1000,"2048x2048-height":696,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode-668x465.gif","card_image-width":668,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-vscode.gif","wide_image-width":1000,"wide_image-height":696}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p class=\"graf graf--p\">Visual Studio Code is very popular among web developers (most of us in the ArcGIS API for JavaScript team use it), so Kelly and I thought we should create an extension for VSCode with all these code snippets that we use quite often.<\/p>\n<p class=\"graf graf--p\">Aaand there it is: ?<a href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=Esri.arcgis-jsapi-snippets\">ArcGIS API for JavaScript Snippets VSCode Extension<\/a> ?<\/p>\n<p class=\"graf graf--p\">How to use it? In VSCode, go to Extensions, search for <code class=\"markup--code markup--p-code\">arcgis api for javascript<\/code> and press the install button. Check out the list of code snippets that we added there. In your app, type in the prefix of the code snippet you want to add and press <code class=\"markup--code markup--p-code\">Tab<\/code>\u00a0. That should create the code snippet with the placeholders just like in the animated gif above.<\/p>\n<p class=\"graf graf--p\">You can have a look at all the snippets in the <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/github.com\/Esri\/arcgis-js-vscode-snippets\/tree\/master\/snippets\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/Esri\/arcgis-js-vscode-snippets\/tree\/master\/snippets\">Github repository<\/a>. If you want to suggest code snippets to us, please create an issue or open up a pull request. If you want to learn how to create your own code snippets, but not necessarily add them to our extension then read more about it in this <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/code.visualstudio.com\/docs\/editor\/userdefinedsnippets\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/code.visualstudio.com\/docs\/editor\/userdefinedsnippets\">VSCode tutorial<\/a>.<\/p>\n"},{"acf_fc_layout":"content","content":"<h2>Code snippets for the browser console<\/h2>\n<p>Sometimes a layer doesn\u2019t show up in the app or you\u2019d like to get that nice viewpoint to reuse it somewhere else, or maybe you even want to change things interactively (light settings, quality mode, etc.) just to try things out. That\u2019s when these code snippets are useful. And for those that use Google Chrome for debugging, you can even store these code snippets in the developer tools in the <code class=\"markup--code markup--p-code\">Snippets<\/code> tab.<\/p>\n"},{"acf_fc_layout":"image","image":{"ID":561922,"id":561922,"title":"chrome-snippets","filename":"chrome-snippets.gif","filesize":849637,"url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","link":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\/chrome-snippets","alt":"chrome snippets","author":"7011","description":"Storing and running code snippets in Google Chrome developer tools. This code snippet prints the camera position.","caption":"Storing and running code snippets in Google Chrome developer tools. This code snippet prints the camera position.","name":"chrome-snippets","status":"inherit","uploaded_to":561822,"date":"2019-07-08 12:37:12","modified":"2019-07-08 13:53:44","menu_order":0,"mime_type":"image\/gif","type":"image","subtype":"gif","icon":"https:\/\/www.esri.com\/arcgis-blog\/wp-includes\/images\/media\/default.png","width":697,"height":601,"sizes":{"thumbnail":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets-213x200.gif","thumbnail-width":213,"thumbnail-height":200,"medium":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","medium-width":303,"medium-height":261,"medium_large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","medium_large-width":697,"medium_large-height":601,"large":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","large-width":697,"large-height":601,"1536x1536":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","1536x1536-width":697,"1536x1536-height":601,"2048x2048":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","2048x2048-width":697,"2048x2048-height":601,"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets-539x465.gif","card_image-width":539,"card_image-height":465,"wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/chrome-snippets.gif","wide_image-width":697,"wide_image-height":601}},"image_position":"center","orientation":"horizontal","hyperlink":""},{"acf_fc_layout":"content","content":"<p>The most useful code snippet is the one for getting access to the view. That will grant you super powers, like access to the layers and their views and so on:<\/p>\n<pre><code style=\"padding: 0.5em; color: #333; background: #f8f8f8;\">\r\n  <span style=\"color: #333; font-weight: bold;\">const<\/span> view = <span style=\"color: #0086b3;\">require<\/span>(<span style=\"color: #d14;\">\"esri\/views\/View\"<\/span>).views.getItemAt(<span style=\"color: #008080;\">0<\/span>);\r\n\r\n  <\/code><\/pre>\n<p>Now you can for example display all the layers in your map with their corresponding index:<\/p>\n<pre><code style=\"padding: 0.5em; color: #333; background: #f8f8f8;\">\r\n  view.map.allLayers.forEach((layer, index) =&gt; {\r\n    <span style=\"color: #0086b3;\">console<\/span>.log(<span style=\"color: #d14;\">`<span style=\"color: #333; font-weight: normal;\">${index}<\/span> -&gt; <span style=\"color: #333; font-weight: normal;\">${layer.title}<\/span>`<\/span>);\r\n  });\r\n\r\n  <\/code><\/pre>\n<p>If a layer doesn&#8217;t display, you can get access to it and check if the LayerView was created successfully:<\/p>\n<pre><code style=\"padding: 0.5em; color: #333; background: #f8f8f8;\">\r\n  <span style=\"color: #333; font-weight: bold;\">const<\/span> layer = view.map.allLayers.getItemAt(index);\r\n\r\n  view.whenLayerView(layer)\r\n    .then((layerView) =&gt; <span style=\"color: #0086b3;\">console<\/span>.log(layerView))\r\n    <span style=\"color: #998; font-style: italic;\">\/\/ if there were problems with the layerview, you'll get an error here<\/span>\r\n    .catch(<span style=\"color: #0086b3;\">console<\/span>.error);\r\n\r\n  <\/code><\/pre>\n"},{"acf_fc_layout":"content","content":"<p class=\"graf graf--p\">You can explore more code snippets like this in this <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/github.com\/RalucaNicola\/code-snippets-arcgis-api-js\/blob\/master\/debug-snippets\/snippets.md\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/RalucaNicola\/code-snippets-arcgis-api-js\/blob\/master\/debug-snippets\/snippets.md\">file<\/a>. If you want to learn how to add them to the <code class=\"markup--code markup--p-code\">Snippets<\/code> section in Chrome developer tools, you will probably find <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/developers.google.com\/web\/tools\/chrome-devtools\/javascript\/snippets\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/developers.google.com\/web\/tools\/chrome-devtools\/javascript\/snippets\">this tutorial<\/a> useful. A similar environment for Mozilla Firefox is Scratchpad. You can learn more about it <a class=\"markup--anchor markup--p-anchor\" href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Tools\/Scratchpad\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Tools\/Scratchpad\">here<\/a>.<\/p>\n<p>And that\u2019s about it! As a summary, in this blog post we presented:<\/p>\n<ul>\n<li>\u00a0a new <a class=\"markup--anchor markup--li-anchor\" href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=Esri.arcgis-jsapi-snippets\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/marketplace.visualstudio.com\/items?itemName=Esri.arcgis-jsapi-snippets\">VSCode extension<\/a> with common ArcGIS API for JavaScript code snippets that are useful while developing applications.<\/li>\n<li>a <a class=\"markup--anchor markup--li-anchor\" href=\"https:\/\/github.com\/RalucaNicola\/code-snippets-arcgis-api-js\/blob\/master\/debug-snippets\/snippets.md\" target=\"_blank\" rel=\"noopener\" data-href=\"https:\/\/github.com\/RalucaNicola\/code-snippets-arcgis-api-js\/blob\/master\/debug-snippets\/snippets.md\">list of code snippets<\/a> that are useful while debugging ArcGIS API for JavaScript applications directly in the browser console.<\/li>\n<\/ul>\n<p>Have fun coding!<\/p>\n"}],"authors":[{"ID":7011,"user_firstname":"Raluca","user_lastname":"Nicola","nickname":"Raluca Nicola","user_nicename":"raluca_zurich","display_name":"Raluca Nicola","user_email":"RNicola@esri.com","user_url":"https:\/\/raluca-nicola.net\/","user_registered":"2018-03-02 00:19:07","user_description":"Raluca works as a web cartographer with the Geo Experience Center team at Esri. She loves to play around with web technologies and visualization styles. If she's not in front of the computer, she's probably somewhere up in the mountains.","user_avatar":"<img data-del=\"avatar\" src='https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/7VkWXsZ3_400x400.jpg' class='avatar pp-user-avatar avatar-96 photo ' height='96' width='96'\/>"},{"ID":4801,"user_firstname":"Kelly","user_lastname":"Hutchins","nickname":"Kelly","user_nicename":"kelly","display_name":"Kelly Hutchins","user_email":"khutchins@esri.com","user_url":"","user_registered":"2018-03-02 00:16:25","user_description":"Software developer on the instant apps team building apps that help you share your Online content. Outside of work I enjoy spending time trail running with my dogs.","user_avatar":"<img data-del=\"avatar\" src='https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2024\/04\/IMG_3695-213x200.jpg' class='avatar pp-user-avatar avatar-96 photo ' height='96' width='96'\/>"}],"related_articles":[{"ID":79711,"post_author":"7011","post_date":"2017-10-04 08:00:30","post_date_gmt":"2017-10-04 08:00:30","post_content":"","post_title":"Speed up your JavaScript development with autocasting","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"speed-up-your-javascript-development-with-autocasting","to_ping":"","pinged":"","post_modified":"2020-01-29 01:50:21","post_modified_gmt":"2020-01-29 09:50:21","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.esri.com\/arcgis-blog\/products\/product\/uncategorized\/speed-up-your-javascript-development-with-autocasting\/","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"},{"ID":76291,"post_author":"6561","post_date":"2017-03-28 05:00:32","post_date_gmt":"2017-03-28 05:00:32","post_content":"","post_title":"Take advantage of the JavaScript symbol playground","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"take-advantage-of-the-javascript-symbol-playground","to_ping":"","pinged":"","post_modified":"2018-05-11 18:12:56","post_modified_gmt":"2018-05-11 18:12:56","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.esri.com\/arcgis-blog\/products\/product\/uncategorized\/take-advantage-of-the-javascript-symbol-playground\/","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"},{"ID":317602,"post_author":"7451","post_date":"2018-10-16 07:25:12","post_date_gmt":"2018-10-16 14:25:12","post_content":"","post_title":"Using TypeScript with the ArcGIS API for JavaScript","post_excerpt":"","post_status":"publish","comment_status":"closed","ping_status":"closed","post_password":"","post_name":"using-typescript-with-the-arcgis-api-for-javascript","to_ping":"","pinged":"","post_modified":"2018-10-15 11:18:10","post_modified_gmt":"2018-10-15 18:18:10","post_content_filtered":"","post_parent":0,"guid":"http:\/\/www.esri.com\/arcgis-blog\/?post_type=blog&#038;p=317602","menu_order":0,"post_type":"blog","post_mime_type":"","comment_count":"0","filter":"raw"}],"card_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2017\/10\/live-by-the-code.png","wide_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-banner.png"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.9 (Yoast SEO v25.9) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Code snippets for ArcGIS API for JavaScript - discover how to use them<\/title>\n<meta name=\"description\" content=\"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Useful code snippets for ArcGIS API for JavaScript\" \/>\n<meta property=\"og:description\" content=\"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\" \/>\n<meta property=\"og:site_name\" content=\"ArcGIS Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/esrigis\/\" \/>\n<meta property=\"article:modified_time\" content=\"2020-01-29T09:40:29+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@ESRI\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":[\"Article\",\"BlogPosting\"],\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\"},\"author\":{\"name\":\"Raluca Nicola\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/e8fe39abb687cde59f7f1296fbfb24a4\"},\"headline\":\"Useful code snippets for ArcGIS API for JavaScript\",\"datePublished\":\"2019-07-08T13:28:22+00:00\",\"dateModified\":\"2020-01-29T09:40:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\"},\"wordCount\":8,\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"keywords\":[\"Developer\",\"EsriRDZurich\",\"JavaScript\"],\"articleSection\":[\"Mapping\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\",\"name\":\"Code snippets for ArcGIS API for JavaScript - discover how to use them\",\"isPartOf\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\"},\"datePublished\":\"2019-07-08T13:28:22+00:00\",\"dateModified\":\"2020-01-29T09:40:29+00:00\",\"description\":\"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.esri.com\/arcgis-blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Useful code snippets for ArcGIS API for JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#website\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"name\":\"ArcGIS Blog\",\"description\":\"Get insider info from Esri product teams\",\"publisher\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#organization\",\"name\":\"Esri\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png\",\"width\":400,\"height\":400,\"caption\":\"Esri\"},\"image\":{\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/esrigis\/\",\"https:\/\/x.com\/ESRI\",\"https:\/\/www.linkedin.com\/company\/5311\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/e8fe39abb687cde59f7f1296fbfb24a4\",\"name\":\"Raluca Nicola\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/7VkWXsZ3_400x400.jpg\",\"contentUrl\":\"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/7VkWXsZ3_400x400.jpg\",\"caption\":\"Raluca Nicola\"},\"description\":\"Raluca works as a web cartographer with the Geo Experience Center team at Esri. She loves to play around with web technologies and visualization styles. If she's not in front of the computer, she's probably somewhere up in the mountains.\",\"sameAs\":[\"https:\/\/raluca-nicola.net\/\",\"https:\/\/www.linkedin.com\/in\/raluca-nicola-cartography\/\",\"https:\/\/x.com\/nicolaraluk\"],\"url\":\"https:\/\/www.esri.com\/arcgis-blog\/author\/raluca_zurich\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Code snippets for ArcGIS API for JavaScript - discover how to use them","description":"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.","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:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","og_locale":"en_US","og_type":"article","og_title":"Useful code snippets for ArcGIS API for JavaScript","og_description":"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.","og_url":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","og_site_name":"ArcGIS Blog","article_publisher":"https:\/\/www.facebook.com\/esrigis\/","article_modified_time":"2020-01-29T09:40:29+00:00","twitter_card":"summary_large_image","twitter_site":"@ESRI","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["Article","BlogPosting"],"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#article","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript"},"author":{"name":"Raluca Nicola","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/e8fe39abb687cde59f7f1296fbfb24a4"},"headline":"Useful code snippets for ArcGIS API for JavaScript","datePublished":"2019-07-08T13:28:22+00:00","dateModified":"2020-01-29T09:40:29+00:00","mainEntityOfPage":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript"},"wordCount":8,"publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"keywords":["Developer","EsriRDZurich","JavaScript"],"articleSection":["Mapping"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","url":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","name":"Code snippets for ArcGIS API for JavaScript - discover how to use them","isPartOf":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#website"},"datePublished":"2019-07-08T13:28:22+00:00","dateModified":"2020-01-29T09:40:29+00:00","description":"Discover how to use code snippets in Visual Studio Code or directly in the browser console to speed up your ArcGIS API for JavaScript web app development.","breadcrumb":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.esri.com\/arcgis-blog\/"},{"@type":"ListItem","position":2,"name":"Useful code snippets for ArcGIS API for JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.esri.com\/arcgis-blog\/#website","url":"https:\/\/www.esri.com\/arcgis-blog\/","name":"ArcGIS Blog","description":"Get insider info from Esri product teams","publisher":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.esri.com\/arcgis-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.esri.com\/arcgis-blog\/#organization","name":"Esri","url":"https:\/\/www.esri.com\/arcgis-blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/Esri.png","width":400,"height":400,"caption":"Esri"},"image":{"@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/esrigis\/","https:\/\/x.com\/ESRI","https:\/\/www.linkedin.com\/company\/5311\/"]},{"@type":"Person","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/e8fe39abb687cde59f7f1296fbfb24a4","name":"Raluca Nicola","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.esri.com\/arcgis-blog\/#\/schema\/person\/image\/","url":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/7VkWXsZ3_400x400.jpg","contentUrl":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2018\/04\/7VkWXsZ3_400x400.jpg","caption":"Raluca Nicola"},"description":"Raluca works as a web cartographer with the Geo Experience Center team at Esri. She loves to play around with web technologies and visualization styles. If she's not in front of the computer, she's probably somewhere up in the mountains.","sameAs":["https:\/\/raluca-nicola.net\/","https:\/\/www.linkedin.com\/in\/raluca-nicola-cartography\/","https:\/\/x.com\/nicolaraluk"],"url":"https:\/\/www.esri.com\/arcgis-blog\/author\/raluca_zurich"}]}},"text_date":"July 8, 2019","author_name":"Multiple Authors","author_page":"https:\/\/www.esri.com\/arcgis-blog\/products\/developers\/mapping\/code-snippets-arcgis-api-javascript","custom_image":"https:\/\/www.esri.com\/arcgis-blog\/app\/uploads\/2019\/07\/code-banner.png","primary_product":"Developers","tag_data":[{"term_id":43161,"name":"Developer","slug":"developer","term_group":0,"term_taxonomy_id":43161,"taxonomy":"post_tag","description":"","parent":0,"count":39,"filter":"raw"},{"term_id":549072,"name":"EsriRDZurich","slug":"esrirdzurich","term_group":0,"term_taxonomy_id":549072,"taxonomy":"post_tag","description":"","parent":0,"count":96,"filter":"raw"},{"term_id":24921,"name":"JavaScript","slug":"javascript","term_group":0,"term_taxonomy_id":24921,"taxonomy":"post_tag","description":"","parent":0,"count":151,"filter":"raw"}],"category_data":[{"term_id":22941,"name":"Mapping","slug":"mapping","term_group":0,"term_taxonomy_id":22941,"taxonomy":"category","description":"","parent":0,"count":2683,"filter":"raw"}],"product_data":[{"term_id":36831,"name":"ArcGIS Maps SDK for JavaScript","slug":"js-api-arcgis","term_group":0,"term_taxonomy_id":36831,"taxonomy":"product","description":"","parent":36601,"count":361,"filter":"raw"},{"term_id":36601,"name":"Developers","slug":"developers","term_group":0,"term_taxonomy_id":36601,"taxonomy":"product","description":"","parent":0,"count":761,"filter":"raw"}],"primary_product_link":"https:\/\/www.esri.com\/arcgis-blog\/?s=#&products=developers","_links":{"self":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/561822","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog"}],"about":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/types\/blog"}],"author":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/users\/7011"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/comments?post=561822"}],"version-history":[{"count":0,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/blog\/561822\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/media?parent=561822"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/categories?post=561822"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/tags?post=561822"},{"taxonomy":"industry","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/industry?post=561822"},{"taxonomy":"product","embeddable":true,"href":"https:\/\/www.esri.com\/arcgis-blog\/wp-json\/wp\/v2\/product?post=561822"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}