I have an array of objects below. This is the raw data
const data = [
{id:1, sItem:"This is javascript", status:"trending"},
{id:2, sItem:"javascript is fun", status:"trending"},
{id:3, sItem:"learning javascript", status:"trending"},
{id:4, sItem:"how to code in javascript", status:"trending"},
{id:5, sItem:"javascript will rule", status:"trending"},
{id:6, sItem:"javascript can do anything", status:"trending"}
]
And I want to search the sItem properties with the keyword javascript and reorder them so that where ever javascript comes at the start of sItem that element should come first with index 0. Other objects starting with javascript should come next followed by the rest of the array objects.
expected o/p
const data = [
{id:2, sItem:"javascript is fun", status:"trending"},
{id:5, sItem:"javascript will rule", status:"trending"},
{id:6, sItem:"javascript can do anything", status:"trending"},
{id:1, sItem:"This is javascript", status:"trending"},
{id:3, sItem:"learning javascript", status:"trending"},
{id:4, sItem:"how to code in javascript", status:"trending"}
]
I have tried to filter array objects
const search = "javascript" data.filter(obj => Object.values(obj).some(val => val.includes(search)))
any suggestion will be useful.