.pop() Method on Global Array

    Dec 10 2012 | 9:26 pm
    How can I pop() or shift() a globally declared array in a function? I get no error, but it also does nothing. I need to access this array from multiple functions, so I've declared it globally. From within other functions I can look up values in the array, and I can traverse the entire array as a collection with a for(...) loop. .length isn't returning a correct value either.
    Thanks, Andrew
    Here's a sample:
    Here's the javascript:
    var bars = new Array();
    var RFID = new String;
    function bang() {
    	for(var bar in bars) {
    		post("RF: " + bar + ", Length: " + bars[bar] + "n");
    function NewRF(rf,l) {
    function GetBar(rf) {
    	post("Length: " + l + "n");
    function Remove() {
    	post("Removing: " + n + "n");

    • Dec 10 2012 | 9:30 pm
      Here's the javascript with line breaks.
    • Dec 11 2012 | 12:39 pm
      It seems that pop only pops array elements that have been pushed. Splice(), likewise only works on elements that have been pushed. If you intersperse pushed and 'regularly' assigned elements, pop and splice will act only on those pushed skipping over the others. Insert the line: bars.push(l); before or after: bars[rf]=l; in function NewRF() to see.
      Is this a bug or is this in the Javascript spec? The example here: http://www.w3schools.com/jsref/jsref_splice.asp , while for a browser, doesn't require the elements to've been pushed first. I found another example where pop doesn't require pushing. I haven't found any examples of pop in Max.
      Thanks, Andrew
    • Dec 11 2012 | 2:30 pm
      The .length property only reports pushed elements as well. Is this by design?