I can not understand what the problem is. We look at a simple code:
var nabor = $('#category'); var items = $('#items'); var data = { "Набор услуг A": ['1 Услуга из набора A', '2 Услуга из набора A', '3 Услуга из набора A'], "Набор услуг B": ['1 Услуга из набора B', '2 Услуга из набора B', '3 Услуга из набора B'], } var uslugi = Object.keys(data); for (var i = 0; i < uslugi.length; i++) { nabor.append('<p>' + uslugi[i] + '</p>'); } $('#category p').on('click', function() { var uslugiiznabora = data[$(this).text()]; console.log(uslugiiznabora); items.length = 0; for (var i = 0; i < uslugiiznabora.length; i++) { items.append('<p>' + uslugiiznabora[i] + '</p>'); } }); <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Everything goes well until the last for loop (var i = 0; i <uslugiiznabora.length; i ++) - it does not work, i.e. data is not displayed. See if you run the following before the loop, for example: items.append('<p>' +uslugiiznabora[0]+ '</p>') , which essentially displays the data of the first item. But why this cycle does not work - I can not understand.
$('#category')and$('#items')- ArchDemon amitems.length = 0;lineitems.length = 0;- Air