Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

find method javascript

// .find method only accepts a callback function 
// and returns the first value for which the function is true.
const cities = [
  "Orlando",
  "Dubai",
  "Denver",
  "Edinburgh",
  "Chennai",
  "Accra",
  "Denver",
  "Eskisehir",
];

const findCity = (element) => {
  return element === "Denver";
};

console.log(cities.find(findCity));
//Expected output is 4 (first instance of "Denver" in array)
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #find #method #javascript
ADD COMMENT
Topic
Name
7+3 =