My sort function doesn't work if one of the attribute has no value: E.G:
JS:
function sortEventsByOrder(a,b) {
const startA = parseInt($(a).data('order'));
const startB = parseInt($(b).data('order'));
return startA - startB;
}
$('#eventList').html($('#eventList li').sort(sortEventsByOrder))
HTML:
<html>
<head>
<link rel="stylesheet" href="lib/style.css">
<script src="lib/script.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
</head>
<body>
<ul id="eventList">
<li data-order="5">Element 5</li>
<li data-order="">Element 3</li>
<li data-order="6">Element 6</li>
<li data-order="1">Element 1</li>
<li data-order="2">Element 2</li>
<li data-order="4">Element 4</li>
</ul>
</body>
</html>
enter image description here As you can see from screen shoot only sort from 6.
How can I sort the empty values to the bottom? or how to get around this issue?
Thanks.