I have this array:
let productKeys = [ "aff_link", "availability", "brand", "date_add", "date_upd", "description", "image_link", "link", "price", "product_type", "title" ];
And another array called preDefinedHeader
:
let preDefinedHeader = ['image_link', 'title', 'price', 'brand', 'link'];
Now, I want to sort the productKeys
array based on the preDefinedHeader
array key order only if any preDefinedHeader
key exist in productKeys
array.
so the output should be now;
['image_link', 'title', 'price', 'brand', 'link', 'aff_link', 'availability', 'description', 'date_add', 'date_upd', 'product_type'];
I know how to sort normally is something like:
productKeys.sort()
But can not get any idea how to sort like I want. Please help me.