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
.