I'm having trouble passing an array as an argument of a function:
function test() {
var array1 = ["1","2"];
var show = "<p>Show: <a href=# onClick='showArray("+array1+")'>Click to show array</a></p>";
}
So I need to have an onClick as it is there, but when I pass an array and call the function
function showArray(array) { alert (array.length); }
Returns nothing. Why not work?
EDIT:
function test() {
var array1 = [];
array1[0] = {
"type" : 0,
"message" : "example",
"from" : "path1",
"count" : 1,
"isChecked": false
};
array1[1] = {
"type" : 2,
"message" : "example",
"from" : "path2",
"count" : 50,
"isChecked": false
};
var show = "<p>Show: <a href=# onClick='showArray(["+array1+"])'>Click to show array</a></p>";
}
showArray(array1)such that the function uses the contents of thearray1variable at the time the event occurs? Or do you want the click event to callshowArray(["1","2"])such that the function uses the array values as they were at the time the element was created (ignoring any changes to thearray1variable that may have happened since)?