Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

creating the find method javascript

let arr = ["Bill", "Russel", "John", "Tom", "Eduard", "Alien", "Till"];
Array.prototype.myFind = function (callback) {
  for (let i = 0; i < this.length; i++) {
    if ( true == callback(this[i], i, this)) {
      return {element:this[i],index:i,array:this};
    }
  }
};
let {element,index,array} = arr.myFind((element) => element[0] === "T");

console.log(`This is ${element} in index of ${index} in array ${array}`);
 Run code snippetHide results
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #creating #find #method #javascript
ADD COMMENT
Topic
Name
6+1 =