Example: If I use the code below it works for the whole word "gorilla". How do I get it to work with "gor" or "illa" or "orill"...? ...(equivalent to a str like "%gor%" in mysql for example)
const jungle = [ { name: "frog", threat: 0 }, { name: "monkey", threat: 5 }, { name: "gorilla", threat: 8 }, { name: "lion", threat: 10 } ]; const names = jungle.map(el => el.name); // returns true document.write(names.includes("gorilla"));
by Ruy Hoffmann in StackOverflow on July 05, 2022 . Answer You can use find (or filter )
const jungle = [ { name: "frog", threat: 0 }, { name: "monkey", threat: 5 }, { name: "gorilla", threat: 8 }, { name: "lion", threat: 10 } ]; const names = (partial) => jungle.find(el => el.name.includes(partial)).name; //You can also use ...