Home > Software design >  How can I make my react search engine to accept both upper and lower case letters?
How can I make my react search engine to accept both upper and lower case letters?

Time:07-19

Hi there my react application is a todolist and has a search engine to filter notes, currently it works if you search for the note but in lower case, how could I make it accept both upper and lower case?

For example, for the javaScript note, it would find it whether I put JAVAscrIPT or jAVAscriPT.

This is my code

const App = () => {
  const [notes, setNotes] = useState([]);
  const [searchText, setSearchText] = useState('');
  const [showNote, setShowNote] = useState(true); //eslint-disable-lint

  const addNote = (inputText, text) => { 
    const date = new Date();
    const newNote = {
      id: nanoid(),
      title: inputText,
      text: text,
      date: date.toLocaleString()
      
    }
    const newNotes = [newNote, ...notes];
    setNotes(newNotes)
  }
  const filterNotes = notes.filter((noteText) => noteText.title.toLowerCase().includes(searchText)); 

//rest of code

A greeting and thanks in advance!

CodePudding user response:

You forgot to use toLowerCase on searchText

const filterNotes = notes.filter((noteText) => noteText.title.toLowerCase().includes(searchText.toLowerCase())); 
  • Related