Split string based on spaces and read that in angular2

Viewed 78868

I am creating a pipe in angular2 where I want to split the string on white spaces and later on read it as an array.

let stringToSplit = "abc def ghi";
StringToSplit.split(" ");
console.log(stringToSplit[0]);

When I log this, I always get "a" as output. Where I am going wrong?

3 Answers

i created this npm package for it: https://www.npmjs.com/package/search-string-eerg

    function customSearch(s, p) {
      let x = p.split(" ");
        var find = true;
        for (var partIndex in x) {
    if (s.toLowerCase().indexOf(x[partIndex]) > -1) {
      // Let this item feature in the result set only if other parts of the
      // query have been found too
      find = find && true;
    } else {
      // Even if a single part of the query was not found, this item
      // should not feature in the results
      find = false;
    }
     }
     return find;
}
Related