@E18e/Array.Prototype.Find

1.0.5Last update Aug 9, 2024
by@e18e

Array.prototype.find Codemod

Introduction

This codemod replaces instances of using a custom implementation to find elements in an array with the built-in Array.prototype.find method. By utilizing native JavaScript features, it reduces unnecessary dependencies and improves the performance and readability of the codebase.

Before

const findElement = (array, predicate) => {
for (let i = 0; i < array.length; i++) {
if (predicate(array[i])) {
return array[i];
}
}
return undefined;
};
const result = findElement(myArray, element => element.id === 1);

After

const result = myArray.find(element => element.id === 1);

Build custom codemods

Use AI-powered codemod studio and automate undifferentiated tasks for yourself, colleagues or the community

background illustrationGet Started Now