<?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: Quinn Sissler</title>
    <description>The latest articles on DEV Community by Quinn Sissler (@qsissler).</description>
    <link>https://dev.to/qsissler</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%2F894018%2Fa40d6776-aa32-4d1d-8094-f81a85d56ce0.png</url>
      <title>DEV Community: Quinn Sissler</title>
      <link>https://dev.to/qsissler</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/qsissler"/>
    <language>en</language>
    <item>
      <title>Waiting on a Promise.. Async and Await in JavaScript</title>
      <dc:creator>Quinn Sissler</dc:creator>
      <pubDate>Mon, 31 Oct 2022 00:02:33 +0000</pubDate>
      <link>https://dev.to/qsissler/waiting-on-a-promise-async-and-await-in-javascript-37ng</link>
      <guid>https://dev.to/qsissler/waiting-on-a-promise-async-and-await-in-javascript-37ng</guid>
      <description>&lt;h2&gt;
  
  
  Why use Async and Await?
&lt;/h2&gt;

&lt;p&gt;By default, Javascript runs synchronously. This means each operation will wait to run until the previous operation is completed. For example, running these two lines of code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YNsnBwcH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xefkeo3044br96ehuesl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YNsnBwcH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xefkeo3044br96ehuesl.png" alt='Console-logging "Hello" and "World"' width="452" height="114"&gt;&lt;/a&gt;&lt;br&gt;
will always result in this output in the console:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ViqKht6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c82x8vz6me9z51ywm13d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ViqKht6Y--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c82x8vz6me9z51ywm13d.png" alt="Hello World" width="150" height="84"&gt;&lt;/a&gt;&lt;br&gt;
Line 1 is run first and Line 2 follows.&lt;/p&gt;

&lt;p&gt;However, sometimes we need our code to run asynchronously. Enter: async and await!&lt;/p&gt;

&lt;h2&gt;
  
  
  Async and Await
&lt;/h2&gt;

&lt;p&gt;Async and await are used with promises. Placing the async keyword before a function ensures that function will return a promise. The await keyword can only be used inside an async function. Anything after the await keyword tells Javascript to wait until the promise resolves and returns its results. So when may we want to use async and await?&lt;/p&gt;

&lt;h2&gt;
  
  
  Putting it in Practice
&lt;/h2&gt;

&lt;p&gt;While completing our capstone projects for bootcamp, I was helping a friend brainstorm some possible ways for her app to function. She wanted a user to click on a dog they were interested in adopting and then fill out an adoption form. We decided to have the initial click event create a post request, essentially joining her user and the adoptable pup and then  push the user to another page where they could input more information. However, her post function would push the user to the form page before the promise resolved, meaning we did not have the id for the newly created donation form yet and therefore could not use that id in our url and then again in our future patch request once the user completed their form. To solve this issue, we were introduced to async and await!&lt;/p&gt;

&lt;p&gt;First, we added the async keyword to our function. We set our fetch to a constant (res) and added the await keyword in front of the fetch. We then declared a new constant (data) and set that to our res.json(), including the await keyword once more. The await keyword tell JavaScript not to continue on to the next operation until the prior operation is resolved. &lt;/p&gt;

&lt;p&gt;We then created a function aptly named redirect that pushes the user to the page where they can update the rest of the form information. Lastly, we invoke the redirect function using the data we received from our promise after it is parsed to json.&lt;/p&gt;

&lt;p&gt;Our final code:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZVQ8-Q1C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/satmna4brvwwa0kdobgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZVQ8-Q1C--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/satmna4brvwwa0kdobgy.png" alt="Async and Await Code" width="838" height="852"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, async and await is a great tool to use when the need arises for JavaScript code to be able to run asynchronously. While today we saw just one great example of using async and await, there are many other ways it can be utilized, which I look forward to using in the future.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dependent: :Destroy to the Rescue!</title>
      <dc:creator>Quinn Sissler</dc:creator>
      <pubDate>Wed, 12 Oct 2022 13:53:13 +0000</pubDate>
      <link>https://dev.to/qsissler/dependent-destroy-to-the-rescue-5433</link>
      <guid>https://dev.to/qsissler/dependent-destroy-to-the-rescue-5433</guid>
      <description>&lt;h2&gt;
  
  
  Dependent: :Destroy
&lt;/h2&gt;

&lt;p&gt;In Rails, Active Record associations can easily connect our models, allowing for common operations to be streamlined. (For more on Active Record associations, check out my blog post on them &lt;a href="https://dev.to/qsissler/associate-with-me-active-record-associations-4l5h"&gt;here&lt;/a&gt;!) One option that can be added to these associations is the dependent destroy option. When an object is deleted from your database, dependent: :destroy will call destroy on all associated objects for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use dependent destroy?
&lt;/h2&gt;

&lt;p&gt;During Phase 3 of Bootcamp, my partner and I created a word game that asked the user to choose the word that matched the picture on the screen. Our User model has_many :games and each Game belongs_to :user. Our User was able to delete themselves from the database but every time we deleted a User, the rest of our application would break. We finally narrowed down our bug to having orphaned Game instances left in our database. Our orphaned Game instances no longer had an associated User, since that User was deleted. After solving this problem in a much more complicated way, our instructor introduced us to a much better and built-in option: dependent: :destroy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dependent: :Destroy to the rescue!
&lt;/h2&gt;

&lt;p&gt;Dependent: :Destroy is added to your has_many association declaration like so:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2XRpo2Jp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzmq0kdnz9rorf04l49z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2XRpo2Jp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jzmq0kdnz9rorf04l49z.png" alt="Dependent Destroy Code Example" width="584" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With this option added, whenever a User is deleted all of the Game instances that are associated with that User are also deleted. Ensuring you leave no orphaned data behind is as simple as that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do I add Dependent: :Destroy?
&lt;/h2&gt;

&lt;p&gt;The dependent: :destroy option should never be added to a belongs_to association that is connected to a has_many association of another class. Doing so can lead to orphaned data. The dependent: :destroy option should be added to the association that you want to also be deleted when you delete the "parent" instance. For example, in another project I had instances of Trips and each of those Trips has_many :items. When I deleted a Trip from the database, I wanted all Items associated with that Trip to be deleted as well. To ensure this, I added the dependent destroy option to my Trip class, on my has_many :items association: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EeMHnY1S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h316b0gp9sgma90a98ge.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EeMHnY1S--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h316b0gp9sgma90a98ge.png" alt="Dependent Destroy Items Code" width="618" height="170"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In summary, dependent: :destroy is a great and easily implemented option to ensure you leave no orphaned data behind.&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://guides.rubyonrails.org/association_basics.html"&gt;Rails Guide: Active Record Associations&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Associate with Me: Active Record Associations</title>
      <dc:creator>Quinn Sissler</dc:creator>
      <pubDate>Fri, 16 Sep 2022 12:57:23 +0000</pubDate>
      <link>https://dev.to/qsissler/associate-with-me-active-record-associations-4l5h</link>
      <guid>https://dev.to/qsissler/associate-with-me-active-record-associations-4l5h</guid>
      <description>&lt;h2&gt;
  
  
  Associate with Me!
&lt;/h2&gt;

&lt;p&gt;Active Record is an incredibly powerful ORM library. One of the many ways we can use Active Record is to help us simplify our code when using common operations between two associated models. Let's consider a simple school application that includes a model for teachers and a model for students. Every teacher has many students and every student belongs to a teacher. Our table model could look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jjsUSFcX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdp7sjuul6yt0rof0dqk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jjsUSFcX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kdp7sjuul6yt0rof0dqk.png" alt="Teacher and Student Table Model" width="880" height="365"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our model declarations without Active Record associations would look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--RIadTRk2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bglwgcb9h5wo9w573fa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--RIadTRk2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3bglwgcb9h5wo9w573fa.png" alt="Teacher and Student classes" width="238" height="320"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  One to Many
&lt;/h2&gt;

&lt;p&gt;The above example shows a one-to-many relationship. To create this association with Active Record, we would declare our models like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--l6-xk34---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5mgio9ufhhrkmpa373d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--l6-xk34---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/w5mgio9ufhhrkmpa373d.png" alt="Teacher and Student classes with Associations" width="538" height="400"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The belongs_to association creates a one-directional connection between the models. With belongs_to, each student in our example model now "knows" its teacher.&lt;/p&gt;

&lt;p&gt;The has_many association is typically used in conjunction with the belongs_to association. With has_many, each teacher in our example model now "knows" its students.&lt;/p&gt;

&lt;p&gt;With just one line of code added to each class, we now have many built in methods that allow us to effortlessly access related data.&lt;/p&gt;

&lt;h2&gt;
  
  
  What now?
&lt;/h2&gt;

&lt;p&gt;Now we can use our built in Active Record methods to access related information.&lt;/p&gt;

&lt;p&gt;We can ask a teacher about their students.&lt;br&gt;
We can also ask a student about their teacher.&lt;/p&gt;

&lt;p&gt;Let's create a teacher instance for Mrs. Smith:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---NqpkQry--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pmz68rpfhfs4n5nztwf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---NqpkQry--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5pmz68rpfhfs4n5nztwf.png" alt="Mrs. Smith Instance" width="880" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to access all of the students that are associated with Mrs. Smith all we have to do is:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2bnAEYKm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11wxdrflji0wwmvrm1le.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2bnAEYKm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/11wxdrflji0wwmvrm1le.png" alt="Mrs. Smith's Students" width="314" height="88"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Yes! It's that easy!&lt;/p&gt;

&lt;p&gt;Let's create a student instance for Johnny:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A4s9ed4x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohpf16sxq0v3enr29txm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A4s9ed4x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ohpf16sxq0v3enr29txm.png" alt="Johnny Instance" width="880" height="81"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to find out who Johnny's teacher is, all we have to do is:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--jDASHZjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9js7awdl4y6tigh711h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--jDASHZjz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9js7awdl4y6tigh711h.png" alt="Johnny's Teacher" width="232" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We can even take it a step further and access Johnny's teacher's name:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vwjlD6G7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyckyoolk1za4909knvy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vwjlD6G7--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyckyoolk1za4909knvy.png" alt="Johnny's Teacher's Name" width="320" height="62"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Active Record is a wonderfully efficient tool that simplifies our code when writing association methods for our associated models. Our example today barely scratches the surface on what Active Record can do and I encourage you to check out their documentation to learn more!&lt;/p&gt;

&lt;p&gt;Sources:&lt;br&gt;
&lt;a href="https://guides.rubyonrails.org/association_basics.html"&gt;Rail Guides&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Filter Out the Fear: filtering arrays in JavaScript</title>
      <dc:creator>Quinn Sissler</dc:creator>
      <pubDate>Thu, 25 Aug 2022 20:57:00 +0000</pubDate>
      <link>https://dev.to/qsissler/filter-out-the-fear-filter-in-javascript-n8e</link>
      <guid>https://dev.to/qsissler/filter-out-the-fear-filter-in-javascript-n8e</guid>
      <description>&lt;h1&gt;
  
  
  filter()
&lt;/h1&gt;

&lt;p&gt;As a beginning developer, I felt intimidated by the filter method. While filter can be a daunting array iterator to learn, after mastering the filter method, I appreciate what a powerful and useful tool it is. If you are fearful of the filter method too, read on and let me help you filter out your fear!&lt;/p&gt;

&lt;h3&gt;
  
  
  Simply Put
&lt;/h3&gt;

&lt;p&gt;Simply put, filter is a method that allows us to filter out one or more items from a larger collection based on certain criteria. &lt;/p&gt;

&lt;p&gt;Let's start with an example of the filter method using a simple array of numbers:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZUEguAGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqw40stck71npjkc2pox.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZUEguAGi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vqw40stck71npjkc2pox.png" alt="Simple array of numbers" width="558" height="82"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For example's sake, let's remove the number 3 from this array using the filter method.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--faeIP8Sh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4g68tf1abp9vjdqkszr7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--faeIP8Sh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4g68tf1abp9vjdqkszr7.png" alt="Filter example" width="690" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the above example, we call filter on our array of numbers. Then, we state that for each number in our array, return all numbers that are not equal to 3. This line of code would return the following array:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lFdNPr9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb1iwyjg8ndbo3y8upsy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lFdNPr9p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rb1iwyjg8ndbo3y8upsy.png" alt="Filtered array" width="198" height="76"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Upping the Ante Marge
&lt;/h3&gt;

&lt;p&gt;A simple example is great for helping us to see how the filter method functions but now let's use filter with a larger data set.&lt;/p&gt;

&lt;p&gt;Here we have an array of objects. More specifically, it is an array of Harry Potter novels. Each book object includes the title, author, page total, and series number.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hpJoEntr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uatdewnpj4qwzxktsm41.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hpJoEntr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uatdewnpj4qwzxktsm41.png" alt="Book Objects" width="880" height="1578"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's pretend we want to read the 4th book in the series (which also happens to be my personal favorite!) but we cannot remember what the book title is. Let's use the filter method to help us:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eOnQbrEh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtmibbarcb1nhizz34hp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eOnQbrEh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dtmibbarcb1nhizz34hp.png" alt="Filter on Book Array" width="858" height="70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We call .filter on our array of Harry Potter book objects. Filter will look at each book object, check to see if its series number is 4. If the series number is not 4, filter says, "See Ya!" and moves on to the next book object. If the series number is 4, filter says, "Come aboard!" and keeps that object in the array.&lt;/p&gt;

&lt;p&gt;This is the filtered array that would be returned to us given the above code:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gHpf_vXB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs1vjcp8shn0mx0v9ccj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gHpf_vXB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gs1vjcp8shn0mx0v9ccj.png" alt="Filtered Series 4" width="736" height="310"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We have our filtered array with the only book object whose series number is 4, which just so happens to be... The Goblet of Fire!&lt;/p&gt;

&lt;p&gt;Typically, we would set this new filtered array to a variable name like so: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BSC3QC4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6mao846x7ydb94b2xzcy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BSC3QC4p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6mao846x7ydb94b2xzcy.png" alt="Assigned Array" width="880" height="53"&gt;&lt;/a&gt;This allows us to access the filtered array where we may need it. We'll see how this idea is utilized in our next example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Go Big or Go Shopping
&lt;/h3&gt;

&lt;p&gt;The previous examples have been enlightening but it's time to see the filter method work in the scope of something we are all familiar with: filtering clothing items by category. My bootcamp project partner and I recently developed a closet application using React that allows the user to filter their closet based on clothing category, i.e. tops, bottoms, shoes, etc. &lt;/p&gt;

&lt;p&gt;Here you can see an example of our clothing item on the page, as well as the item object:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eeaMnmJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2lr980g2i28vxhpxm74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eeaMnmJG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2lr980g2i28vxhpxm74.png" alt="Clothing on Page" width="622" height="958"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kHRPxFns--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c40oo41i5uesycy61kup.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kHRPxFns--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c40oo41i5uesycy61kup.png" alt="Clothing Object" width="880" height="194"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Utilizing a dropdown menu, the user can change which items are shown on the page based on the selected clothing category.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ND06Ujno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzy26cly4q3pvuk4ucc7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ND06Ujno--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vzy26cly4q3pvuk4ucc7.png" alt="Dropdown menu" width="288" height="108"&gt;&lt;/a&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z8FPeYqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m34036un1z4exlnir4nr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z8FPeYqq--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/m34036un1z4exlnir4nr.png" alt="All Categories" width="298" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When a user chooses a specific category from the dropdown, the filter method is utilized to display only the clothing items of that chosen category. &lt;/p&gt;

&lt;p&gt;Here is the code that makes this behind the scenes magic happen:&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C0bhHoz1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cu12tk6os4aamqt65mh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C0bhHoz1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cu12tk6os4aamqt65mh.png" alt="Clothing filter example" width="880" height="154"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;First, we set our new filtered array to a variable named "clothesToDisplay". This allows us to use our filtered array to render only the clothes with the chosen category on our page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Next, we call filter on our original clothes array, which includes every clothing object we created. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then, for each item in this clothing array, if our chosen category is "All", we want to return true. This means if there is no specific category selected, return all of the items in the original array. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Finally, we return only the items from our array whose category is the same as the selected category. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;*It is important we use the toLowerCase() method because we are using the strict equality operator to compare our categories. Our clothing object's value for the category key begin with a lowercase letter, but our category dropdown options begin with an uppercase letter. We must call the toLowerCase method to ensure they are exactly equal when comparing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Conclusion:
&lt;/h3&gt;

&lt;p&gt;The filter method is an incredible array iterator that should not be feared! After learning how this method can be utilized in a variety of ways, I hope I have helped filter out some of your fear and you can happily filter whenever and wherever the need may arise!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Loop For a While: For and While Loops in JavaScript</title>
      <dc:creator>Quinn Sissler</dc:creator>
      <pubDate>Thu, 04 Aug 2022 16:08:00 +0000</pubDate>
      <link>https://dev.to/qsissler/loop-for-a-while-for-and-while-loops-in-javascript-2a30</link>
      <guid>https://dev.to/qsissler/loop-for-a-while-for-and-while-loops-in-javascript-2a30</guid>
      <description>&lt;h1&gt;
  
  
  Looping Through Life
&lt;/h1&gt;

&lt;p&gt;In the year and a half I took computer science courses in college, looping was my Achilles heel. There seemed to be so many different little parts and I struggled to understand how they all worked together. As I restarted my journey to become a software engineer, just the thought of looping filled me with dread. With this blog post, I am going to conquer my fear, further my understanding, and hopefully yours too!&lt;/p&gt;

&lt;h2&gt;
  
  
  What is a loop?
&lt;/h2&gt;

&lt;p&gt;At its core, looping is a way to do the same action more than once. I always say "work smarter, not harder" and loops help us to do that! If manually programming what you want to do each time is like walking up the stairs, then loops are the escalator, doing most of the hard work for us. There are quite a number of loops you can use in JavaScript but today I will focus on a for loop and a while loop.&lt;/p&gt;

&lt;h2&gt;
  
  
  The For Loop
&lt;/h2&gt;

&lt;p&gt;The for loop has 4 different statements. Its basic structure looks like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--u4FrCO2r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6fxpxgpwgxclt8g0e51.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--u4FrCO2r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c6fxpxgpwgxclt8g0e51.png" alt="Basic For Loop Structure" width="758" height="126"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Initialization:&lt;/strong&gt; This is what is executed first. It can start loop counters and more complex expressions, but often it is used to declare a counter variable. Basically, it tells the loop what it needs to know or do to start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; This is what tells the loop to continue! As long as this condition is true, the loop continues to loop some more. Once this condition is false, the loop comes to a complete stop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iteration:&lt;/strong&gt; This is what is executed at the end of each loop iteration. Often it involves incrementing or decrementing the counter variable you set in the initialization part of the for loop.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The three above statements are all separated by a semicolon.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loop Body:&lt;/strong&gt; This is the code that runs each time you go around the loop.&lt;/p&gt;

&lt;p&gt;Let's look at a simple example:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A3aenun2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fzi1o1unhimit3mkfwn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A3aenun2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8fzi1o1unhimit3mkfwn.png" alt="For Loop Example" width="716" height="116"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this example, the &lt;strong&gt;initialization&lt;/strong&gt; is setting the variable of lives equal to 5. I imagine this to be how many lives you might start with while playing a video game.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;condition&lt;/strong&gt; in this example states as long as lives is greater than zero continue to run. That means if lives is one or more the loop will loop again. Once lives reaches zero, the loop will stop.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;iteration&lt;/strong&gt; states that after every loop happens, decrement lives by one. So once a loop occurs, there will be one less life.&lt;/p&gt;

&lt;p&gt;In this &lt;strong&gt;loop body&lt;/strong&gt;, we are just console logging a string that lets the user know how many lives they have remaining. &lt;/p&gt;

&lt;p&gt;The result of this for loop in the console would be: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--X1IOzCL6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pw0zkih9f8cyyf0bgtc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--X1IOzCL6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8pw0zkih9f8cyyf0bgtc.png" alt="For Loop Result" width="394" height="186"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the first console log shows the initialization of lives at 5. The last console log shows lives at 1 which means our loop did not run when lives reached 0, which is exactly what we wanted.&lt;/p&gt;

&lt;h2&gt;
  
  
  The While Loop
&lt;/h2&gt;

&lt;p&gt;The while loop is similar to the for loop but it only has two statements. Its basic structure looks like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2IyBqyR8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7alt9ak7ih9au5q3iwyw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2IyBqyR8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7alt9ak7ih9au5q3iwyw.png" alt="While Loop Structure" width="294" height="114"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Condition:&lt;/strong&gt; This is exactly like the condition in our for loop. If this condition is true, the loop will continue. If this condition is false, the loop stops.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loop Body:&lt;/strong&gt; Just like in our for loop, this is the code that will run every time your loop loops!&lt;/p&gt;

&lt;p&gt;Let's use our lives example from before but this time we will use a while loop:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--rdpIUq3E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3n7dj14fux6c8enxvys.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--rdpIUq3E--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v3n7dj14fux6c8enxvys.png" alt="While Loop Example" width="710" height="230"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Our while loop looks similar to our for loop but there are some definite differences:&lt;/p&gt;

&lt;p&gt;1.) Our variable initialization (let lives = 5) is done outside of our loop. &lt;br&gt;
2.) Our iteration (lives--) is set inside of the loop body.&lt;/p&gt;

&lt;p&gt;Even with these differences, our results are the same:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I_RDYh4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3hgwxb7vojtfrxvez20.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I_RDYh4l--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b3hgwxb7vojtfrxvez20.png" alt="While Loop Results" width="372" height="182"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion:&lt;/strong&gt; I don't know about you but I feel more confident in my ability to understand and write JavaScript loops already! While there are so many more looping methods you can use in Javascript than I covered here, the for and while loops are a great place to start.&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Loops_and_iteration"&gt;Loops and Iteration&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_loop_while.asp"&gt;JavaScript While Loop&lt;/a&gt;&lt;br&gt;
&lt;a href="https://www.w3schools.com/js/js_loop_for.asp"&gt;JavaScript For Loop&lt;/a&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
