React-Native: Check if string contains string
<p>My goal is it to create a search ListView with JSON Data.
This is working but I have a tiny problem with the search function.
When I type in a word, it has to be exactly the same word, which is in the Array of the ListView.
The main problem is that I have to type in the correct word.
For example: when the word <em>stackoverflow</em> is one item of the Array, I have to type in <em>stackoverflow</em> to find this item.
But I want to get the Item also when I type in <em>stack</em> or <em>flow</em> or <em>stacko</em> for example.</p>

<p>This is my code:</p>

<pre><code>    filterDatasource(event)
  {
      var searchString = event.nativeEvent.text.toLowerCase();
      if (searchString != "")
      {

          var content = this.state.loadedContent;
          var searchResultsArray = [];

          for (var i = 0; i &lt; content.length; i++) {


            var detailArray = content[i];
            const gattung = detailArray.Gattung;
            const zugnummer = detailArray.Zugummer;
            const ab = detailArray.ab;
            const bis = detailArray.bis;
            const wochentag = detailArray.Wochentag;
            const zeitraum = detailArray.Zeitraum;


            if (searchString.contains(ab.toLowerCase())) //searchString.indexOf(ab) &gt;= 0
            {

                //alert('gefunden');
                searchResultsArray.push(detailArray);
                this.setState({ dataSource: ds.cloneWithRows(searchResultsArray) });

            }


          }

      }
      else {

        this.setState({ dataSource: ds.cloneWithRows(this.state.loadedContent) });

      }
  },
</code></pre>