How to make array show only 5 attributes?

Need to get data from an array displayed only when the search for him. Not sure what this code is responsible for it. No need to load all the data or to limit 5.

// Attributes
$('#mm_attribute_new').autocomplete({
 'delay': 250,
 'source': function(request, response) {
$.ajax({
 url: 'index.php?route=seller/account-product/jxAutocompleteAttributes&filter_name=' + encodeURIComponent(request),
 dataType: 'json',
 success: function(json) {
 var existing_attrs = [];
 $.map($(document).find('.mm_attribute').not('.ffSample'), function(attribute_row) {
existing_attrs.push($(attribute_row).find('input[name^="product_attribute"][name$="[name]"]').val());
});

 response($.map(json, function(item) {
 if($.inArray(item.name existing_attrs) == -1) {
 return {
 category: item.attribute_group,
 label: item.name
 value: item.attribute_id
}
}
}));
}
});
},
 'select': function(item) {
$(this).parents('#mm_product_attributes').find('.mm_clone').click();
 var newAttr = $(this).parents('#mm_product_attributes').find('.form-group:last');
newAttr.find('input[name$="[attribute_id]"]').val(item['value']);
newAttr.find('input[name^="product_attribute"][name$="[name]"]').val(item['label']);
newAttr.find('label').append(item['label']);
newAttr.find('textarea').focus();
$(this).blur();
}
 });
April 19th 20 at 11:59
1 answer
April 19th 20 at 12:01
Try to localize the problem clearly, because if You are not sure that this is the code that needs to be repaired, it meets even harder to guess where the problem is.
Now you can understand that in the ajax success handler data come from the argument json, and this json is processed in the function $.map. Means in advance it is necessary to leave from json first five items and then pass them to the map. Ideally, the five elements necessary to give from the backend and not be at the level of the frontend.
Use the debugging capabilities of js scripts (console.log, debugger)

Find more questions by tags jQuery