So I have this code below. Whenever I click the button, it goes to the render_initialize_board and console.logs only the first element of the array fixed. How to pass the whole array to the function using onclick in javascript?
function render_initialize_board(N,fixed){
console.log(fixed);
}
N = 4;
var fixed = [0,1,0,0]
$("#header ul").append('<li><a href="#'+N+'" data-toggle="tab" onclick="render_initial_board('+N+','+fixed+')">'+ N +'</a></li>');
$("#header ul").append(`<li><a href="#${N}" data-toggle="tab">${N}</a></li>`); $("#header ul a").on('"click", function (e) { render_initialize_board(N, [0,1,0,0]); });. It's hard to give a definitive answer since there is little context in the question. Providing a minimal reproducible example will go a long way in getting the best answer.toString()method of the non-string. Therefore'render_initial_board('+N+','+fixed+')'will be'render_initial_board(4,0,1,0,0)'sincearr.toString()is equivalent toarr.join(',').render_initialize_board, but you calledrender_initial_board, which is not defined, in theonclick.