

It's worth noting though that it will execute that code for each item that is in the list that returns true so make sure you compensate for that in the code you want executed.Įdit- you could also convert this to a function set it up to pass arguments that are the multiple things you check to see if the string includes and just have it return true or false and you can do whatever with that information outside of the function. 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. This method accepts a search value as a parameter, and returns true if the value is either contained in the array on which it is called, or if it exists as a substring of the string object on which it is called. Var res4 = text.filter(data => data.includes(conditions) || data.includes(conditions)) Ĭonsole.log(res4) // ĭef an old thread but still getting newer replies. The includes () method is part of both the Array and String prototypes. 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. You could also do individual export.Not the best answer and not the cleanest, but I think it's more permissive. Let's create a file named module.js (filename can be anything) with the following content: // program to include JS file into another JS fileĮxport
