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.

  • Edit your message. Add $('#category') and $('#items') - ArchDemon am
  • one
    items.length = 0; line items.length = 0; - Air
  • Here it is, inattention))) Thank you !!! - Dem0n.Hunter
  • You're welcome - Air
  • Continuing the theme, tell me, how can I do it right now so that the data is taken from the json file? I know. that you need to use the $ .getJSON function, but have not figured it out yet. How can I get exactly the array that is needed (as in the example above) we put in the variable var uslugi = Object.keys (data); - Dem0n.Hunter pm

0