I have 2 arrays. FIRST looks like:
const arrOjObjects = [
{text: "HUF", value: 300.3803314317},
{text: "GBP", value: 0.7925201485},
{text: "IDR", value: 14127.9996377796},
{text: "ILS", value: 3.5020374898},
{text: "DKK", value: 6.7633795164}]
Second looks like:
const arr = ["ILS, "DKK"]
I need to sort arrOjObjects by some rule, if the elements of the object text match the element of the array arr, then the object must be first and all other objects behind it
I need some sort rule, which will sort my arr to this state:
const arrOjObjects = [
{text: "ILS", value: 3.5020374898}, // ILS is in arr
{text: "DKK", value: 6.7633795164} // DKK is in arr
{text: "HUF", value: 300.3803314317},
{text: "GBP", value: 0.7925201485},
{text: "IDR", value: 14127.9996377796},
]
Thanks for answers!
X.filter(arr.includes(x.text)).concat(X.filter(!arr.includes(x.text)))