What do you want to save?
Add Code snippet
New code examples
-
Other 2021-10-22 10:53:06
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... Add solution