I’m using the jQuery library, and attempting to push items to an array:
< onclick ="setFacet('myarray','val');">AOC
var myarray = [];
function setFacet(arr, bb) {
for (var i=0; i< arr.length; i++)
if (arr[i] == bb)
return true;
arr.push(bb);
return false;
}
I get this in chrome:
Object myarray has no method ‘push’
Oh, I think I found the issue. In your
onclick, you’re calling the function with two strings. The first argument should be an array rather than'myarray'.If you just get rid of the quotes (and if
myArrayis in the global scope) it should work. That is, have it look like this: