title: JavaScript Helper | startsWith( ) is not a function
body: <p>I need to write a <strong>helper function</strong> that loops through an array of objects &amp; filters all names that meet established criteria. In my case all names that begin with <code>Zach</code></p>
  
  <p>Array example:
  </p>
  
  <pre><code>const users = [
    {
      firstName: "Zach",
      id: 1,
      lastName: "Volsk"
    },
    {
      firstName: "Surly",
      id: 2,
      lastName: "Furious"
    },
  
    {
      firstName: "Zach",
      id: 3,
      lastName: "Tee"
    },
    {
      firstName: "Eve",
      id: 4,
      lastName: "Zelda"
    },
  
    {
      firstName: "Zachary",
      id: 5,
      lastName: "Toys"
    }
  ];
  </code></pre>
  
  <p>I'm able to retrieve the desired result applying filter and map directly i.e:
  </p>
  
  <pre><code>const filterZach = users
    .filter(user =&gt; user.firstName.startsWith("Zach"))
    .map(user =&gt; {
      return `&lt;p&gt;${user.firstName} ${user.lastName}&lt;/p&gt;`;
    }).join(""); // get rid of comas
  </code></pre>
  
  <p>Desired Result: <code>Zach Volsk, Zach Tee, Zachary Toys</code></p>
  
  <p><strong>However,</strong> when I tried to abstract that functionality into a helper method so that I can use it elsewhere in my code:
  i.e:
  </p>
  
  <pre><code>// helper
  function filteredNames(arr, str) {
    return arr.filter(i =&gt; i.startsWith(str));
  }
  </code></pre>
  
  <p>I get an error saying: <em>i.startsWith is not a function</em>
  </p>
  
  <pre><code>const filterZach = filteredNames(users, "Zach") // i.startsWith is not a function
  const renderZach = filterZach.map(user =&gt; {
      return `&lt;p&gt;${user.firstName} ${user.lastName}&lt;/p&gt;`;
    }).join("");
  </code></pre>
  
  <p><strong>Question:</strong> Could you please help understand the reason for this issue showing me an alternative to accomplish my goal using a helper function?</p>
  
  <p>I'm not married to the <code>startsWith( )</code> method and I'd love to learn other ways to go about this. Reduce perhaps? </p>
  
  <p>here's a <a href="https://codesandbox.io/s/q7nn6k00w9" rel="nofollow noreferrer">code sandbox</a></p>