So I have an array of HTML links;
[
"<a href=\"...\" target=\"_blank\">foo</a>",
"<a href=\"...\" target=\"_blank\">apple</a>",
"<a href=\"...\" target=\"_blank\">cucumber</a>"
]
And I want to sort it based on the user-facing output of it (i.e. the a
tag's content);
[
"<a href=\"...\" target=\"_blank\">apple</a>",
"<a href=\"...\" target=\"_blank\">cucumber</a>",
"<a href=\"...\" target=\"_blank\">foo</a>"
]
I imagine I'd have to strip the HTML tags and then .sort()
that, but I have no idea how to then reconcile that with the original array. How do I do this?