I am having some trouble with getting what I want out of jQuery. I have an ajax call that returns and array of arrays.
my jQuery looks something like this...
$.each(search_results, function()
{
$.each(this, function(results)
{
var first_name = '';
var last_name = '';
$.each(this, function(index, value)
{
if(index == 3 )
{
last_name = value;
}
if(index == 5)
{
first_name = value;
var contact_name = first_name + " " + last_name;
var result_item = '<li class="list-group-item">' + contact_name + '</li>';
$(id).append(result_item);
}
});
});
});
This works and is all well and good, but I'm returning hundreds of records. Looping through each element in the array to pickout two to five elements seems like WAY too much work.
Is there a way to do something like this...
$.each(search_results, function()
{
$.each(this, function(results)
{
$.each(this, function(result)
{
var first_name = result[5];
var last_name = result[3];
var contact_name = first_name + " " + last_name;
var result_item = '<li class="list-group-item">' + contact_name + '</li>';
$(id).append(result_item);
}
});
});
});
I found a similar question here, but the answer seems odd to me. There has to be a way....
I hope this helps more
Array / JSON Structure:
Object { search_results: […] }
search_results : Array [ […], […], […], … ]
[0..99]
0 : Array [ "all", "stuff", "I want", … ]
var(orconst,let) before first_name and last_name by the way$.each(search_resultsis the same assearch_results.forEach(