I need to filter objects in the array by their value. The value comes from the input (event.target.value).
const people = [
{ firstName: "John", lastName: "Lu", age: 50, eyeColor: "green" },
{ firstName: "Mary", lastName: "Smith", age: 70, eyeColor: "blue" },
{ firstName: "Nick", lastName: "Joy", age: 45, eyeColor: "green" },
{ firstName: "Ann", lastName: "Smith", age: 10, eyeColor: "brown" },
];
I need to check every value in the array. If the user writes lu, the result should be (lu in blue and Lu in the lastName)
I use indexOf but get empty array.
const inputData = event.target.value;
const newResult = people.filter((obj) => Object.values(obj).indexOf(inputData !== -1));
Could you please help me. I looked through many issues but can’t solve my problem.