I am running into an issue, I have a similar array of Strings in JS:
var myArray = [\"bedroomone\", \"bedroomonetwo\", \"bathroom\"];
And I
You could also use the search() method
Finds the first substring match in a regular expression search.
(method) String.search(regexp: string | RegExp): number (+1 overload)
const filterList = (data, query) => {
return data.filter(name => name.toLowerCase().search(query.toLowerCase()) !== -1);
};
String.prototype.indexOf:
var PATTERN = 'bedroom',
filtered = myArray.filter(function (str) { return str.indexOf(PATTERN) === -1; });
Regexp:
var PATTERN = /bedroom/,
filtered = myArray.filter(function (str) { return PATTERN.test(str); });
String.prototype.includes (only in moderm browsers):
var PATTERN = 'bedroom',
filtered = myArray.filter(function (str) { return str.includes(PATTERN); });
Improved Microfed's answer to this
var textToSearch = 'bedroom';
var filteredArray = myArray.filter((str)=>{
return str.toLowerCase().indexOf(textToSearch.toLowerCase()) >= 0;
});
var bedrooms = myArray.filter(name => name.includes('bedroom'))