JavaScript sort array based on subarray value