Sometimes, we want to search an array for a substring match with JavaScript.
In this article, we’ll look at how to search an array for a substring match with JavaScript.
How to search an array for a substring match with JavaScript?
To search an array for a substring match with JavaScript, we call the filter and includes methods.
For instance, we write
const items = ["item 1", "thing", "id-3-text", "class"];
const matches = items.filter((s) => s.includes("thi"));
to call items.filter with a callback that checks if string s in items includes 'thi' with includes.