I have an ajax function as:
$.ajax({
url: 'get_days.php',
type: 'post',
dataType:"json",
data: { firstdate: firstdate,
seconddate: seconddate,
frompartofday: frompartofday,
topartofday: topartofday},
success: function (response) {
if(response.status!='wrong'){
console.log(response.result1);}}});
On server side I am setting the response as
$response['result1']=$currentRange;
where $currentRange is an array. When printing the response using
console.log(response.result1);
Output in console is
['12-19-2022', '12-20-2022']
0:"12-19-2022"
1:"12-20-2022"
length:2
[[Prototype]]:Array(0)
Please help me in accessing the element of this array returned by json with array index.
CodePudding user response:
You can access the elements of an array by bracket notation
someArray[i]
Where someArray
is an array (in your case result1
) and i
is the index (a number) into the array, starting at index 0. For example
result1[0] // gets the first element of the array in your response