title: When using a function and for loop how do I return the first matching value in an object if there are duplicates or similar values?
body: <p>For example, say I have the following duplicates in my dataset and I input <code>name = Finding Your Center</code> as an argument into the below function. I want to return the <code>price</code> of the first matching <code>itemName</code>. Instead of returning 15.00 because 15.00 is the first value that matches the string argument, the above function would return 1500 because it's looping through the entire object data instead of stopping at the first matching/similar value.</p>
  <pre><code> let duplicates = [
        {
          itemName: &quot;Finding Your Center&quot;,
          type: &quot;book&quot;,
          price: 15.00
        },
        {
          itemName: &quot;Finding Your Center&quot;,
          type: &quot;book&quot;,
          price: 1500.00
        }];
  </code></pre>
  <p>Here's my pseudocode and my function so far. This function returns all the values I need expect for using a specific data set.</p>
  <pre><code>// Create priceLookUp function to find price of a single item
  // Give the function two paramenters: an array of items and an item name as string
  // priceLookUp = undefined for nomatching name
  // loop through the items array checking if name = itemName
  // return the price of item name matching string
  // for a matching/similar value the code should stop running at the first value instead of going through the rest of the loop
  
  function priceLookup (items, name){
    let priceOfItem = undefined;
    for (let i = 0; i &lt; items.length; i++) 
    if (name === items[i].itemName) 
    {priceOfItem = items[i].price;}
    return priceOfItem;
  }
  </code></pre>
  <p>How would I get the function as written using a for loop to stop running at the first matching value and not loop through the entire array?</p>