Filter strings in Array based on content

前端 未结 4 1461
予麋鹿
予麋鹿 2020-11-28 14:23

I am running into an issue, I have a similar array of Strings in JS:

var myArray = [\"bedroomone\", \"bedroomonetwo\", \"bathroom\"];

And I

4条回答
  •  甜味超标
    2020-11-28 15:17

    Improved Microfed's answer to this

    var textToSearch = 'bedroom';
    var filteredArray = myArray.filter((str)=>{
      return str.toLowerCase().indexOf(textToSearch.toLowerCase()) >= 0; 
    });
    

提交回复
热议问题