I'm trying to implement a REST application, get a json package and output it to a table, but if at the same time adding a bunch of errors to the data in the array, please say what am I doing wrong?

Code:

var lebelCh = new Array(); var dataCh = new Array(); function showAllElem(arrElem){ $('table').remove(); $('#getChart').remove(); var tbl = "<table id='reportTable'>"; tbl += "<tr><th>№ п/п</th><th>Имя</th><th>Атрибут</th></tr> $.each(arrElem, function(i, el) { tbl += '<tr><td>' + i + '</td><td>' + el.name + '</td><td>' + el.index + '</td></tr>'; lebelCh.push(el.name);//тут выходит ошибка dataCh.push(el.index);//тут выходит ошибка }); tbl += "</table>"; $(tbl).addClass('mytable').appendTo('#reportBlock'); $('#getBtn').after('<button id="getChart">Показать график</button>'); } 

Mistake

 Uncaught ReferenceError: lebelCh is not defined at Object.<anonymous> (main.js:88) at Function.each (jquery-3.3.1.min.js:2) at showAllElem (main.js:86) at Object.success (main.js:33) at u (jquery-3.3.1.min.js:2) at Object.fireWith [as resolveWith] (jquery-3.3.1.min.js:2) at k (jquery-3.3.1.min.js:2) at XMLHttpRequest.<anonymous> (jquery-3.3.1.min.js:2) 

Closed due to the fact that off-topic participants are Roman C , freim , LFC , 0xdb , aleksandr barakin on March 3 at 16:05 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Roman C, freim, LFC, 0xdb, aleksandr barakin
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • "// there is an error here" - NEVER !!! do not say what. - Igor
  • Sorry, fixed. - Vadim
  • one
    array variables are declared in a place that is not visible from the code where you use them - Igor
  • Thank you, I really didn’t get enough of it, made the variables global and everything turned out! - Vadim

0