Day 2: Polyfill for Array.includes()

1 min read ❤️ 0 · 💬 1
#day2 #100daysofcode #javascript

Today, let's work on creating a polyfill for Array.includes() method.

NOTE: Polyfills are code snippets that provide modern functionality to older environments that don't support them.

// test cases
const array = [1, 2, 3, 4, 5];

console.log(array.myIncludes(3)); // Output: true
console.log(array.myIncludes(6)); // Output: false

Enter fullscreen mode Exit fullscreen mode

Plan

To solve this problem, we'll follow these steps:

  • Implement the myIncludes function to iterate through the array and check if the given element exists or not.
  • Create a new property called myIncludes on Array.prototype and assign the function.

Check the comment below to see answer.


Originally published on DEV Community . Read the discussion and share your thoughts there.

© 2026

LinkedIn 𝕏 GitHub