I try playerNameArray.length = 0; this doesn’t empty the array, it makes those values be undefined.
I try playerNameArray = []; this doesn’t empty the array, it makes those values be undefined.
I try var playerNameArray = new Array (); this doesn’t empty the array, it makes those values be undefined.
Maybe the problem is the initial array is public and i try to empty them inside of functions?
Maybe the problem is I need that array to be public in my JavaScript because on my html page I pass the array in a function and the page wont recognize the array if I initialize it inside the function I use it?
I add each array object to a database, but a user should be able to create a new array after inserting the first one. I tried to cheese my insert statement and said if the array element != ‘undefined’ then insert it but it completely ignored that and inserted the undefined.
any suggestions please?
the code is as follows:
var createListCounter = 0;
var playerID = new Array();
var playerNameArray = new Array();
function addToList(espnPlayerID, playerName) {
playerID[createListCounter] = espnPlayerID; playerNameArray[createListCounter] =playerName;
createListCounter++
var url = "";
$('#accumListPlayer').append('<tr><td>'+ playerName + '</td></tr>');
}
then on a button click i iterate through that array and save it t oa db. once that completes, i need the array to have nothing in it. if i still have the original objects in it, they write to the database again.
Setting it equal to
[]ornew Array()overwrites the current value with a blank array.If you are looping the array you can check if it has any elements by testing its length:
You can also test individual elements of the array using the
typeoffunction: