You can also add what to do if it's false in the if statement as well. execute a function, change a variable etc. It will return true if any of those items are in that string and then you can have it do whatever. Const text = ' does this include item3? ' includes to search for multiple things in a string at once.ĭepending on what you are trying to do with it just run a for loop that runs through an array of items you want to check a string for using. I didn't see it on the results and it's one of the easiest ways to use. Var res4 = text.filter(data => data.includes(conditions) || data.includes(conditions)) Ĭonsole.log(res4) // ĭef an old thread but still getting newer replies. You may use again the same filters for a different check Var res3 = text.filter(data => data.includes(conditions) & data.includes(conditions)) filter(data => data.includes(conditions) || data.includes(conditions) || data.includes(conditions)) Ĭonsole.log(res1) // filter(data => data.includes(conditions) || data.includes(conditions) || data.includes(conditions)) filter() works with an array and returns a filtered array (which I find easier to use too). Like if you want to use the same filters for all of your checks.Īctually. Not the best answer and not the cleanest, but I think it's more permissive.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |