Home > Software engineering >  How to use multiple methods in JavaScript at the same time
How to use multiple methods in JavaScript at the same time

Time:10-17

I have an input where you can search for a specific course by its name, for this I use filtering, and also the includes() method, my problem is that I need to apply three methods at the same time, the first method is toLowerCase(), the second is toUpperCase() and the last method is trim()

GetMyCourses() {
  return this.courses.filter(value => {
    return value.title.toLowerCase().includes(this.result);
  });
},

If you leave the toLowerCase method, then it does not give capital names when searching, and vice versa, in addition, if you remove these two methods, then when searching you will need to accurately search for the word

CodePudding user response:

Convert this.result to lower case as well.

GetMyCourses() {
  let result = this.result.toLowerCase()
  return this.courses.filter(value => {
    return value.title.toLowerCase().includes(result);
  });
},
  • Related