<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Stu Finn</title>
    <description>The latest articles on DEV Community by Stu Finn (@stu).</description>
    <link>https://dev.to/stu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F56689%2F2d320c68-de9c-450d-8e06-3fedf453fc95.jpeg</url>
      <title>DEV Community: Stu Finn</title>
      <link>https://dev.to/stu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/stu"/>
    <language>en</language>
    <item>
      <title>Gatsby's awesome new File System Route API</title>
      <dc:creator>Stu Finn</dc:creator>
      <pubDate>Mon, 30 Nov 2020 22:23:45 +0000</pubDate>
      <link>https://dev.to/stu/gatsby-s-awesome-new-file-system-route-api-50k9</link>
      <guid>https://dev.to/stu/gatsby-s-awesome-new-file-system-route-api-50k9</guid>
      <description>&lt;p&gt;I just implemented a very simple version of Gatsby’s &lt;a href="https://www.gatsbyjs.com/docs/file-system-route-api/" rel="noopener noreferrer"&gt;new File System Route API&lt;/a&gt;* and I have to say, I love it.&lt;/p&gt;

&lt;p&gt;Until now, the only way to dynamically create pages in Gatsby has been to use the &lt;a href="https://www.gatsbyjs.com/docs/node-apis/#createPages" rel="noopener noreferrer"&gt;createPages API&lt;/a&gt; inside of the &lt;em&gt;gatsby-node.js&lt;/em&gt; file.  While this works really well, and is still something you will have to use when you have have more complex conditions (e.g. if you only want to create pages for a subset of blogposts) the new &lt;a href="https://www.gatsbyjs.com/docs/file-system-route-api/" rel="noopener noreferrer"&gt;File System Route API&lt;/a&gt; really simplifies things for most of page-creation use cases such as blog posts or in my case, photo albums.&lt;/p&gt;

&lt;p&gt;Here’s the gist:&lt;/p&gt;

&lt;p&gt;I have a bunch of photo albums that I created via my CMS.  Which CMS I used isn’t important here (&lt;em&gt;cough cough&lt;/em&gt; it was &lt;a href="https://www.sanity.io" rel="noopener noreferrer"&gt;Sanity&lt;/a&gt; which you should definitely check out).  What &lt;em&gt;is&lt;/em&gt; important is how I queried for my blogposts using Gatsby’s GraphQL API.  Your data will be structured differently, but this example will give you a sense of things:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;query AlbumsQuery {
  allSanityAlbums {
    edges {
      node {
          title
        slug {
          current
        }
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I’m not going to go into the fine details of &lt;em&gt;how&lt;/em&gt; this API works, I just want to show you that it does, and it’s pretty slick.&lt;/p&gt;

&lt;p&gt;Ok, so now I want Gatsby to somehow loop through each of the SanityAlbums using the “edges” array that’s returned by the above query, then have Gatsby create pages for each album, or “node” and finally use slug.current as the page’s slug.&lt;/p&gt;

&lt;p&gt;Looking at my Gatsby files in VSCode, I have created a folder called “Albums”, and inside that folder I create a React component file using a special syntax for the filename, ie. &lt;em&gt;{SanityAlbums.slug&lt;/em&gt;&lt;em&gt;current}.js&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F95e3z0kdimchp9npgldy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F95e3z0kdimchp9npgldy.png" alt="Screenshot of file structure"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This filename will result in a page with the following url: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F30sd5bclf27415jyr6na.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F30sd5bclf27415jyr6na.png" alt="http://&amp;lt;website-url&amp;gt;/albums/&amp;lt;slug&amp;gt;/"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice that I nested the file in the &lt;em&gt;albums&lt;/em&gt; directory, which provides the url with the /albums/ structure, but you could just as easily make a top-level page by skipping that step and putting the file directly in the &lt;em&gt;pages&lt;/em&gt; directory.&lt;/p&gt;

&lt;p&gt;Ok, you have to admit that the filename looks pretty weird.  Curly brackets? Take a breath ‘cause those curly brackets help make the magic happen. This filename tells Gatsby, “For each of my “SanityAlbums”, create a new page using the component in this file and set the slug to the value of &lt;em&gt;slug.current&lt;/em&gt;. The double underscore is what indicates that we’re using a child property of &lt;em&gt;SanityAlbums.slug&lt;/em&gt;. Why don’t we just write it as {SanityAlbums.slug.current}.js you ask?  &lt;a href="https://www.gatsbyjs.com/docs/file-system-route-api/#underscore-notation" rel="noopener noreferrer"&gt;No idea but it works&lt;/a&gt;! &lt;/p&gt;

&lt;p&gt;Inside the file is a simple React component that is going to render on each of the pages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React from “react”

const Album = ({ data }) =&amp;gt; {
  return &amp;lt;div&amp;gt;{data.sanityAlbums.title}&amp;lt;/div&amp;gt;
}

export const query = GraphQL`
  query($id: String!) {
    sanityAlbums(id: { eq: $id }) {
      title
    }
  }
`

export default Album
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Gatsby automatically queries for the id for each of the nodes, so we can use it in our component’s &lt;a href="https://www.gatsbyjs.com/docs/page-query/" rel="noopener noreferrer"&gt;Page Query&lt;/a&gt; in order to extract the data that we want to use in the component. To keep things simple, I have only queried for the page title but you can access any of your data here.&lt;/p&gt;

&lt;p&gt;And that is seriously it! Honestly, just save your file and your new pages should be live.  By adding this one file and a few lines of code I now have individual pages for each of my photo albums. Amazing.&lt;/p&gt;

&lt;p&gt;Keep in mind that there are still plenty of use-cases when the &lt;em&gt;createPages&lt;/em&gt; API is required, so this isn’t a complete replacement for that but it is sure a great way to get things built even faster.&lt;/p&gt;

&lt;p&gt;More more info on the API, check out the &lt;a href="https://www.gatsbyjs.com/docs/file-system-route-api/" rel="noopener noreferrer"&gt;Gatsby docs&lt;/a&gt;. The folks at Gatsby also have &lt;a href="https://github.com/gatsbyjs/gatsby/tree/master/examples/route-api/src/pages/products" rel="noopener noreferrer"&gt;some really great example code for this &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now go try it out and let me know what you think!&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;EDIT: To use this feature, you'll need to be using Gatsby version 2.26.0 or later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;EDIT: (Feb 17, 2021) A drawback of this approach is that you cannot currently pass custom data to the page via pageContext &lt;a href="https://www.gatsbyjs.com/blog/fs-route-api/" rel="noopener noreferrer"&gt;like you can with the &lt;em&gt;createPages&lt;/em&gt; API&lt;/a&gt;. If you need to do that because, for example, you want to fetch data from an external data source (i.e. not Gatsby's graphQL layer) at build time, you should use the createPages API for now.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>gatsby</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Write your first Google Apps Script with just a few Lines of JavaScript</title>
      <dc:creator>Stu Finn</dc:creator>
      <pubDate>Thu, 23 Jan 2020 18:48:58 +0000</pubDate>
      <link>https://dev.to/stu/write-your-first-google-apps-script-39b7</link>
      <guid>https://dev.to/stu/write-your-first-google-apps-script-39b7</guid>
      <description>&lt;p&gt;A few weeks ago I wrote my  first Google Apps script.&lt;/p&gt;

&lt;p&gt;Liquid error: internal&lt;/p&gt;

&lt;p&gt;It took me longer than I'm willing to admit (mostly because I had no idea how to go about it at first) but by using &lt;a href="https://developers.google.com/apps-script/reference/"&gt;the official docs&lt;/a&gt; as a guide combined with a bit of help from google/stack overflow, I was able to write a simple program that automates a menial task for me.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.google.com/apps-script"&gt;Google Apps Scripts&lt;/a&gt; allows us to programmatically create and customize Google services, from Calendars to Gmail to Spreadsheets and almost everything in-between. My small foray into the world of Google Apps Scripts has shown me just how powerful it can be, and I have barely scratched the surface so far.&lt;/p&gt;

&lt;p&gt;Today I want to create a new script and I’m going to bring you along for the ride so you can see just how straightforward Google Apps Script writing can be with just a little knowledge of JavaScript.&lt;/p&gt;

&lt;h2&gt;
  
  
  The goal
&lt;/h2&gt;

&lt;p&gt;I'd like become more consistent about writing daily notes re: what I’ve accomplished, what I’ve learned, and what has tripped me up. Credit to my dev coach, &lt;a href="https://twitter.com/practicingdev"&gt;Gregory Brown&lt;/a&gt; for encouraging me in this practice and for his helpful article, “&lt;a href="https://www.oreilly.com/radar/an-efficient-approach-to-continuous-documentation/"&gt;An Efficient Approach to Continuous Documentation&lt;/a&gt;”.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we'll do
&lt;/h2&gt;

&lt;p&gt;The script we are going to write together will:&lt;/p&gt;

&lt;p&gt;A) Automatically update a “Daily Notes” survey in Google forms to reflect the current date, and &lt;/p&gt;

&lt;p&gt;B) Email it to us at the end of each work day as a reminder to fill it in.&lt;/p&gt;

&lt;p&gt;Nothing too crazy, right?&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 1: Manually create a survey in Google Forms
&lt;/h2&gt;

&lt;p&gt;While it is entirely possible to programmatically create a new survey, for our purposes we are going to set up our survey manually. Our script will then modify it each day.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://forms.gle/sqT3iqxfEUEtx2YA9"&gt;My survey&lt;/a&gt; has the following five questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;What did you accomplish today?&lt;/li&gt;
&lt;li&gt;What did you learn today?&lt;/li&gt;
&lt;li&gt;What did you get stuck on today?&lt;/li&gt;
&lt;li&gt;How did you feel today? (scale of 1-5)&lt;/li&gt;
&lt;li&gt;Additional notes/thoughts&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ak5eee21--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/n9irsvlv56z5uxygndou.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ak5eee21--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/n9irsvlv56z5uxygndou.jpg" alt="Survey preview"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each day at around 4:00pm I want the title of the survey to be updated to reflect the current date, and then I want it sent to my inbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Fire up the the Google Apps Script Editor
&lt;/h2&gt;

&lt;p&gt;With our survey open and editable, click the drop down menu and select the Script Editor.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BvV0V_a9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gd9ewtyyzs38stkb747d.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BvV0V_a9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/gd9ewtyyzs38stkb747d.gif" alt="Click the drop down menu"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will now be taken to a blank script page.  Rename it to something like “Modify Daily Survey”.&lt;/p&gt;

&lt;p&gt;Google Apps Scripts allows us to create standalone scripts, as well as scripts that are tied to specific files from the start. Because we created the script from within our Google Form, it is already connected to the survey we just created. More on that later!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3: Start slinging code
&lt;/h2&gt;

&lt;p&gt;For reference, you can find the docs for &lt;a href="https://developers.google.com/apps-script/reference/forms"&gt;scripts for Forms here&lt;/a&gt;, and &lt;a href="https://developers.google.com/apps-script/reference/gmail"&gt;scripts for Gmail here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let's create three functions. The first will be the main “app” that will get things initialized. The second function will modify the title of the survey and the third function will send the survey to a specified email address.&lt;/p&gt;

&lt;p&gt;The first function will stay as &lt;strong&gt;myFunction&lt;/strong&gt; for simplicity’s sake. Now we need assign a variable to the active google form. We can do that with:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var dailySurvey = FormApp.getActiveForm();&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now let’s grab today’s date and assign it to a variable:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var currentDate = new Date();&lt;/code&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You may have noticed that I used &lt;em&gt;var&lt;/em&gt; instead of &lt;em&gt;const&lt;/em&gt; or &lt;em&gt;let&lt;/em&gt;.  As far as I understand, Google Apps Scripts uses ES5 and thus it doesn't include all of the cutting-edge ES6 features you may be familiar with. Keep that in mind as we proceed! &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are used to using &lt;code&gt;console.log()&lt;/code&gt; to check your work in the browser, that won’t work here. What you can use instead is &lt;code&gt;Logger.log()&lt;/code&gt;. After you run a script you can view the log from the &lt;strong&gt;View&lt;/strong&gt; menu (Cmd + Enter on a Mac).&lt;/p&gt;

&lt;p&gt;Here's what we've got so far:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunction() {
    // get the active Form that's associated with this script
    var dailySurvey = FormApp.getActiveForm();

    // assign today's date to currentDate
    var currentDate = new Date();

    // convert the date object into a string, 
    //and assign the first 15 characters to a variable (to use in our survey's title)
    var dateString = currentDate.toString().slice(0,15);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;The first time you run a script you may get an “authorization required” pop-up.  Follow the instructions to authorize your script (PSA: The script will be granted access to your google account, so use this with caution if you aren’t the only author of the script!).&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Now that we have access to the survey through &lt;strong&gt;dailySurvey&lt;/strong&gt; and we have the date as a string in &lt;strong&gt;dateString&lt;/strong&gt;,  let’s modify the title of the survey to reflect today’s date.  We will do this in a separate function,  &lt;strong&gt;changeDate()&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function changeDate(survey, date) {

    // Assign text that we'll use in the title with the current date to a variable
    var titleText = "Daily Survey for " + date;

    // Set the title of the survey!
    survey.setTitle(titleText);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom! We are now able to modify the survey title on command! Next up, we want to email the updated survey to ourselves. Let’s create the &lt;strong&gt;sendSurvey()&lt;/strong&gt; function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function sendSurvey(survey, dateString) {
    // grab the URL where the survey is published
    var surveyUrl = survey.getPublishedUrl();

    // the content of our email
    var emailBody = "&amp;lt;p&amp;gt;Stu, it's time to take &amp;lt;em&amp;gt;just a few moments&amp;lt;/em&amp;gt; to reflect on your day.&amp;lt;/p&amp;gt;
                "&amp;lt;p&amp;gt;Here's the link: " + surveyUrl + "&amp;lt;/p&amp;gt;;

    // the subject line content
    var subject =  "Daily Survey for " + dateString;

    // send the email! Note that we can use html in the body of the email using the {htmlBody: emailBody} syntax below.
    GmailApp.sendEmail("[destination email address goes here]", subject,'',{
        htmlBody: emailBody});
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note that you will once again be asked to verify the app when it tries to send you an email. You may also get a warning that the app isn’t verified. Again use an appropriate amount of caution but if you have created it yourself and you know exactly what the script does, by all means proceed.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And here is the full app in all of it’s 39 lines (including blank space &amp;amp; comments!) of glory:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function myFunction() {
  // assign the active form (Daily Survey) to daily Survey
  var dailySurvey = FormApp.getActiveForm();
  var currentDate = new Date();

  // convert the date object into a string, and assihn the first 15 characters to a variable
  var dateString = currentDate.toString().slice(0,15);

  //call the updateDate() function
  changeDate(dailySurvey, dateString);

  // call the sendSurvey() function
  sendSurvey(dailySurvey, dateString);

}

function changeDate(survey, date) {

  // Set the text that we'll use in the title with the current date
  var titleText = "Daily Survey for " + date;
  Logger.log(titleText);
  survey.setTitle(titleText);

}

function sendSurvey(survey, date) {

  // grab the URL where the survey is published
    var surveyUrl = survey.getPublishedUrl();

    // the content of our email
  var emailBody = "&amp;lt;p&amp;gt;Stu, it's time to take &amp;lt;em&amp;gt;just a few moments&amp;lt;/em&amp;gt; to reflect on your day.&amp;lt;/p&amp;gt;&amp;lt;p&amp;gt;Here's the link: " + surveyUrl + "&amp;lt;/p&amp;gt;";

    // the subject line content
    var subject =  "Daily Survey for " + date;

    // send the email! Note that we can use html in the body of the email useing the syntax below
    GmailApp.sendEmail('[destination email address goes here]', subject,'',{
        htmlBody: emailBody});

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Magic! Now when you run the script myFunction() you should get an up-to-date survey in your inbox!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4: Schedule the app to run each day
&lt;/h2&gt;

&lt;p&gt;I have avoided saying any of this is “easy” since what is easy for me today seemed impossibly complicated just a few months ago but I'm not going to lie, this next step is legit easy.&lt;/p&gt;

&lt;p&gt;To schedule the app to run at a specified interval simply go to “Edit/Current Project’s Triggers” and add a custom trigger. That’s it!&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5: Celebrate!
&lt;/h2&gt;

&lt;p&gt;You have now created your first Google Apps Script! Let me know in the comments how it goes for you, and what wondrous things you create with your new superpowers.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>googleapps</category>
    </item>
    <item>
      <title>How to iterate over objects using array methods</title>
      <dc:creator>Stu Finn</dc:creator>
      <pubDate>Fri, 22 Feb 2019 21:16:01 +0000</pubDate>
      <link>https://dev.to/stu/how-to-iterate-over-objects-using-array-methods-662</link>
      <guid>https://dev.to/stu/how-to-iterate-over-objects-using-array-methods-662</guid>
      <description>&lt;p&gt;Arrays are so freaking handy!  They are a great way to store data and they have some really amazing “array methods” like &lt;code&gt;.forEach()&lt;/code&gt; and &lt;code&gt;.map()&lt;/code&gt; (and more) that allow us to easily iterate over an array. Sweet!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sampleArray&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;I&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;love&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="err"&gt;“&lt;/span&gt;&lt;span class="nx"&gt;technology&lt;/span&gt;&lt;span class="err"&gt;”&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nx"&gt;sampleArray&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;word&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// I&lt;/span&gt;
&lt;span class="c1"&gt;// love&lt;/span&gt;
&lt;span class="c1"&gt;// technology&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Objects are super too, in my humble opinion. With key/value pairs we only need a key name and we can get the associated value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;sampleObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;word1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Always&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;word2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;and&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;word3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;forever&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// We can use either dot- or bracket-notation to access values:&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sampleObject&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;word1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;    &lt;span class="c1"&gt;// Always&lt;/span&gt;

&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sampleObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;word3&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;    &lt;span class="c1"&gt;// Forever&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Boom!&lt;/p&gt;

&lt;p&gt;What seems &lt;em&gt;less&lt;/em&gt; awesome, though, is that array methods like &lt;code&gt;.forEach()&lt;/code&gt;, &lt;code&gt;.map()&lt;/code&gt;, etc… don’t work on objects.  Noooooo! &lt;/p&gt;

&lt;p&gt;[Insert sad-face here]&lt;/p&gt;

&lt;p&gt;But don’t despair!  There &lt;em&gt;is&lt;/em&gt; a way to use array methods to easily iterate over objects, using the &lt;code&gt;Object.keys()&lt;/code&gt; method.  Let me explain:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What's Object.keys( ), you say?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Object.keys()&lt;/code&gt; is a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys"&gt;built in Javascript method&lt;/a&gt; that takes any object as a parameter, and returns an array of that object’s keys.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sampleObject&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="c1"&gt;//  [“word1”, “word2”, “word3”] &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right on!&lt;/p&gt;

&lt;p&gt;So as a workaround, we can use the returned array of keys to iterate over our object using an array method such as &lt;code&gt;.forEach()&lt;/code&gt;. Sick!&lt;/p&gt;

&lt;p&gt;Let me show you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// here we now have an array of sampleObject’s keys&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;arrayOfKeys&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Object&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;sampleObject&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  

&lt;span class="c1"&gt;// we can use the key to call up each piece of Object data &lt;/span&gt;
&lt;span class="nx"&gt;arrayOfKeys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt; &lt;span class="nx"&gt;sampleObject&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt; 

&lt;span class="c1"&gt;// Always&lt;/span&gt;
&lt;span class="c1"&gt;// and&lt;/span&gt;
&lt;span class="c1"&gt;// forever&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;WHAAAAAT?!  Beautiful!  *wipes away a single tear*&lt;/p&gt;

&lt;p&gt;Now you know how to easily iterate over an Object using at least one array method. Please use your new powers responsibly!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/116wwYf3ajIvrG/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/116wwYf3ajIvrG/giphy.gif" alt="I love technology"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;For more information on array methods see the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/prototype#Methods"&gt;MDN webdocs&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;To learn about some of the best array methods out there, check out &lt;a href="https://dev.to/frugencefidel/10-javascript-array-methods-you-should-know-4lk3"&gt;this handy article&lt;/a&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many thanks to Wes Bos for pointing this out in his &lt;a href="https://reactforbeginners.com/"&gt;React for Beginners course&lt;/a&gt;. It's a really great course.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>javascript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>100(-ish) Days of Code</title>
      <dc:creator>Stu Finn</dc:creator>
      <pubDate>Fri, 19 Oct 2018 22:03:51 +0000</pubDate>
      <link>https://dev.to/stu/100-ish-days-ofcode-5bp2</link>
      <guid>https://dev.to/stu/100-ish-days-ofcode-5bp2</guid>
      <description>&lt;p&gt;If you have an interest in developing a coding habit or if you want to take your skills to the next level, I highly recommend participating in the &lt;a href="https://www.100daysofcode.com/"&gt;#100DaysOfCode&lt;/a&gt; challenge. The challenge, created by &lt;a href="https://twitter.com/ka11away"&gt;@ka11away&lt;/a&gt;, is designed to help participants develop a daily habit of coding. It also immediately connects you with a global network of people who are also trying to become better developers (or like me developers, period).&lt;/p&gt;

&lt;p&gt;There are only a few main rules for #100DaysOfCode:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Code every day for 100 days for at least an hour.&lt;/li&gt;
&lt;li&gt;Tweet your daily progress to the #100DaysOfCode hashtag.&lt;/li&gt;
&lt;li&gt;Connect with and encourage at least two other people who are also doing the challenge.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For many people, coding for an hour every single day might  seem unrealistic. Maybe you work or study long hours and some days it's just not possible to carve out the extra time. Or maybe like me, you have kids and/or a partner who understandably demand a lot of your time. Whatever your reason, if you're feeling overwhelmed by the idea of coding ever day, I have some good news for you: you're allowed to break the rules! &lt;strong&gt;It is ultimately up to you to define your own metrics of success.&lt;/strong&gt; In the end, the #100DaysOfCode challenge is about finding the best way to develop a solid coding habit. For some people that means coding every single day. And for others it necessarily means breaking the rules.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"It's very flexible, it's up to you. You can definitely do anything you want with it. You don't have to re-start it every time you make a mistake. […] If there is a certain limitation that you know up front, you can write it into the rules of your challenge." &lt;br&gt;
 -  Alexander Kallaway, creator of the #100DaysOfCodeChallenge in Ep. 46 of the FreeCodeCamp podcast&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;People who know me best know that I love to play by the rules. My wife can't handle playing board games with me because I am constantly referring to the rule-book when others are treating the rules as mere suggestions. I appreciate structure and routine and I tend to be more successful when there's a clear framework that I can follow (maybe that's why I like coding so much?). With this in mind, it makes sense to me that I was eager to participate in the #100DaysOfCode challenge when I saw it appear in my Twitter timeline last year.&lt;/p&gt;

&lt;p&gt;One of my main life goals is to have the flexibility to spend ample time with my partner and our kids. Yet when I started the #100DaysOfCode challenge, I routinely found myself taking time away from my family to make sure that I got my coding in on weekends and holidays. I worried that if I skipped a day or two of the challenge, I would have to start over at day one. Eventually I realized that even though I &lt;em&gt;already&lt;/em&gt; had the flexibility to spend time with my family, I was sacrificing it while striving to achieve the same flexibility in my future career as a developer. That didn't make a whole lot of sense to me.&lt;/p&gt;

&lt;p&gt;As a result, I decided to align my goals for the #100DaysOfCode challenge with my longer-term goals. I made a conscious decision to code daily as often as possible but to also spend guilt-free time with my family whenever I needed (or wanted) to. I ended up taking most weekends and school holidays completely away from coding, but I made sure to get back to daily coding as soon as it was possible - usually on the following Monday. And for me, that worked great. I am convinced that this relaxed approach to the challenge helped me to finish all 100 days (even if many of them weren't consecutive), and to establish a habit of coding regularly.&lt;/p&gt;

&lt;p&gt;I realize that everyone's life-demands are unique which means that everyone's criteria for success will be too. And I'm certainly privileged to be able to take time off with my family whenever I want to. Whatever your circumstances are, I hope that you won't be discouraged by the idea of coding for 100 days straight but that you will be willing adjust the challenge so that it works best for you, in order to accomplish your goals.&lt;/p&gt;

&lt;p&gt;In the end, I completed my first round of the 100 days of code in &lt;strong&gt;166 days&lt;/strong&gt;. And I'm super happy about it, so much so that after a break over the summer holidays (my kids we're home every day, after all) I started round #2.&lt;/p&gt;

&lt;p&gt;If you are considering doing the #100DaysOfCode challenge and you're anxious about coding every single day, my advice is to give yourself some slack. Think about why you want to do challenge, and as long as you're achieving the goals that you set for yourself, in my opinion you're doing it right.&lt;/p&gt;




&lt;p&gt;Massive thanks for &lt;a class="comment-mentioned-user" href="https://dev.to/ka11away"&gt;@ka11away&lt;/a&gt;
 for creating the challenge, &lt;a href="https://twitter.com/practicingdev?lang=en"&gt;@practicingdev&lt;/a&gt; for reading this over for me, and to the #100DaysOfCode Twitter community for you continued encouragement and motivation.&lt;br&gt;
Follow me during my second round of the #100DaysOfCode &lt;a href="https://twitter.com/stufinn"&gt;@stufinn&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>100daysofcode</category>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
