I receive the following object that I receive from the source –
["road",[["road",53,"0E"],["roadtrip",53,"1E"],["roadrunner",53,"2E"],["roadster",53,"3E"],["roadside",53,"4E"],["roadrage",53,"5E"],["roadcycling",53,"6E"],["roadsideamerica",53,"7E"]],{"k":1,"q":"lpxvQlflqTsJ-2_PMBLImSpu1PU"}]
Values I want to fetch from the object:
road, roadtrip, roadrunner, roadster and so on.
and here’s the code
$('#query').autocomplete({
source: function( request, response ) {
$.ajax({
type: "GET",
url: , // url for the source
dataType: "json",
data: {
"tags" : request.term
},
success: function( data ) {
related = data[1];
response(data[1][0]);
}
});
}
But I get only the value from the first array of the object?
For eg. road OE
How should iterate to fetch the values of it?
That’s an array not an object and if you JSONLint it:
You can see that the first key is the string “road”, second is an array and the last an object.
The items you are looking for are the first keys of the arrays in the second key of the main array.
Try something like: