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)