score:0

you can split your words in the title field and check against the keyword you provide

in the first example 2 records are returned since inside the keyword string both words are contained within the records

in the second, all records are returned since sale is present in all elements

const items = [{
      title: "used car for sale",
      description: "i am selling a used 2003 honda civic. works well.",
      price: "$1000",
    },
    {
      title: "computer for sale",
      description: "selling a brand new dell computer",
      price: "$800",
    },
    {
      title: "used phone for sale",
      description: "i am selling my iphone 1",
      price: "$400",
    },
  ];


  function filterresults(list, keyword) {
    return list.filter(x => {
      const arr = x.title.tolowercase().split(' ');
      return arr.some(y => keyword.tolowercase().includes(y))

    });
  }

  console.log(filterresults(items, 'computer phone'))
  console.log(filterresults(items, 'computer'))


Related Query

More Query from same tag