My Array looks like this
filtervalue = xy
arr = [{id:123, name:'xyz'}, {id:122, name:'xyy'}, {id:134, name:'zzz'}]
arr.filter((i) =>
name.includes(filtervalue)
);
above gives me the expected output as below
[{id:123, name:'xyz'}, {id:122, name:'xyy'}]
I'm trying to do the same thing with the id. it gives me an error
.includes is not a function.
like, when my filterval = 12
expected output should be as below
[{id:123, name:'xyz'}, {id:122, name:'xyy'}]
how do i achieve this ?
Please use filter function like this.
const filtervalue = 12
const arr = [{id:123, name:'xyz'}, {id:122, name:'xyy'}, {id:134, name:'zzz'}]
const result = arr.filter((val) => val.id.toString().includes(filtervalue.toString()))
console.log(result)