I have created two empty array in jquery and using ajax I'm assigning the values in them suppose there are 2 values in each array assigned by the ajax but they are randomly placed but I'm populating them with the select option so for displaying it well I have to display that array in the efficient way soo here is my code I'm using but not works:-
Code:-
<select id="dropdown">
</select>
var array1 = Array();
var array2 = Array();
$.ajax({
url:"/api/v1/workingspots",
type: "GET",
dataType: 'json',
async: false,
success: function(response){
for (var i = 0; i < response.response.data.length; i++) {
array1 = response.response.data[i].start_time;
array2 = response.response.data[i].end_time;
var res = array1.sort(function(a, b) {
return a > b
});
}
}
});
Error I'm facing :-
Uncaught TypeError: array1.sort is not a function
at Object.success (booking:58)
at i (jquery.min.js:2)
at Object.fireWith [as resolveWith] (jquery.min.js:2)
at A (jquery.min.js:4)
at XMLHttpRequest.<anonymous> (jquery.min.js:4)
at Object.send (jquery.min.js:4)
at Function.ajax (jquery.min.js:4)
at HTMLDocument.<anonymous> (booking:49)
at j (jquery.min.js:2)
at k (jquery.min.js:2)
values I'm assigning to array is:-
//By console.log(array1)
28800
14400
How will I sort both the arrays and assigning there each values produce by both array populate with the select option. Thank you.