How to implement Array.prototype.find? JavaScript Interview Question | Problem Solving | JavaScript Polyfills
@Yomesh Gupta

In this question, the candidate needs to implement a function customFind that mimics the behaviour of Array.prototype.find method.

More about Array.prototype.find

The find() method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.


const array = [5, 12, 8, 130, 44];
const found = array.customFind(element => element > 10);

// prints 12


The customFind takes two parameters

  1. callback function

Function to execute on each value in the array. The function is called with the following arguments:


  • The current element in the array.


  • The index (position) of the current element in the array.


  • The array that customFind was called on.

The callback must return a truthy value to indicate a matching element has been found.

  1. thisArg (Optional)

Object to use as this inside callbackFn.

const input = [1,2,312];

function greaterThanTen(element, index, array) {
  return element > 10;

// customFind(callback, thisArg)
customFind(greaterThanTen, input);


Start the timer, complete your solution, and test it against the test cases provided by the platform. Ideally, you should finish this question within 15 mins. Share your solution with us --

Loading IDE...