I have an array of bookings and need to search for a specific value inside the array using searchValue
.
In this case, I need to check the booking id field. If the booking id matches the searchValue
, then I need to push that object into the result array.
Here's an example of the result array:
Result array example:
let searchValue = "12,13,15"
Result:
[{ name:"user 3", bookingid:12, product: "ui" },
{ name:"user 4", bookingid:13, product: "ef" }]
Expected Output:
Since 12 and 13 are matched in the booking array, the remaining value in the searchValue is "15". Can someone please provide guidance on how to handle this?
let bookingArr = [
{ name:"user 1", bookingid:10, product: "ab" },
{ name:"user 1", bookingid:10, product: "cd" },
{ name:"user 2", bookingid:11, product: "ui" },
{ name:"user 1", bookingid:10, product: "ef" },
{ name:"user 3", bookingid:12, product: "ui" },
{ name:"user 4", bookingid:13, product: "ef" },
];
let searchValue = "12,13,15";
let set = new Set(searchValue.split(",").map(Number)); // for faster lookup
let res = bookingArr.filter(x => set.has(x.bookingid));
console.log(res);
// how can i get not matched searchValue
// expected result notmatchedsearchValue ="15"