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

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

More about Array.prototype.findLast

The findLast() method iterates the array in reverse order and returns the value of the first element that satisfies the provided testing function. If no elements satisfy the testing function, undefined is returned.


const array = [1,2,3,12,13,8];

const greaterThanTen = (element) => element > 10;

// expected output: 13


The customFindLast 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.

customFindLast(callback, thisArg)


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...