Within my messages.json file, I have JSON objects storing chat messages. An example snippet is shown below:
[
{
"sender": "Alice",
"text": "Hello there"
},
{
"sender": "John",
"text": "How's it going?"
}
]
I am trying to locate the index of a specific term within these messages based on user input from a text field. However, running the code snippet below results in receiving "undefined" in the output console.
const handleSearch = (event) => {
const searchResult = messages.filter((message) => {
return message.text.indexOf(event.target.value);
});
console.log(searchResult);
};
What could be causing this unexpected "undefined" outcome?