Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

return the first matching object from an array

function priceLookup(items, name) {

  for (let i = 0; i < items.length; i++) {
    if (name === items[i].itemName) {
      // the return will break the loop and exit the function
      return items[i].price;
    }
  }
  // if loop completes no matches were found
  return "No item found with that name"
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: key codes javascript 
Javascript :: js for await 
Javascript :: import an image in react 
Javascript :: Difference between “ == “ and “ === “ operators. 
Javascript :: how to fetch data redux 
Javascript :: vue multiple slot 
Javascript :: display component in popup angular 8 
Javascript :: vue3 header 
Javascript :: vuejs events modifier 
Javascript :: reisze image expo react native 
Javascript :: address validation in javascript 
Javascript :: node red json array 
Javascript :: adding parameters to url react router 
Javascript :: Movie-app using react 
Javascript :: frames[i] javascript 
Javascript :: how to use $ in javascript 
Javascript :: axios 
Javascript :: like operator mangodb 
Javascript :: adding more than one class react 
Javascript :: create object javascript 
Javascript :: enable javascript chrome 
Javascript :: binary search tree js 
Javascript :: vue js skeleton loading 
Javascript :: mongoose virtual populate 
Javascript :: do while loop javascript 
Javascript :: datatables add row with id 
Javascript :: send an email react native 
Javascript :: split javascript 
Javascript :: delete value from an array javascript 
Javascript :: JavaScript and HTML DOM Reference 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =