remove element from global array

    Dec 02 2016 | 12:33 pm
    Sorry for the pretty noob question, i am trying to build in JS a kind of "intelligent urn". I am stuck in a problem about arrays and global variables.
    If i create an array inside a function it seems to work fine:
    function removeElementInArray() { var localArray = [2,3,4,6]; var splicing = localArray.splice(0, 1); post (localArray[0]); post(); }
    this gives 3 as desired result.
    I want of course to make the preceding function generic and If i create a global array and fill it with arguments of a max message:
    var internalUrn = new Array(); function fillUrn(){ internalUrn = arguments; }
    and I try to apply the same operation:
    function removeElementInArray2() { var splicing = globaUrn.splice(0, 1); post (globalUrn[0]); post(); }
    I get an error message:
    Javascript TypeError: globalUrn.splice is not a function, line xxx
    Seems it must be something simple but i cannot get it. Thanks for help....

    • Dec 02 2016 | 4:39 pm
      Hi Ratox,
      How are you declaring the global object? My guess is that because you make it global, its not an Array but a js object. If you could share a bit more code it would be easier to figure it out.
      You could add an array as a property to the object and then access it like
      // Declare the global object at one of the JS files
      var globalUrn = new Global("global_urn");
            globalUrn.urnArray= [2,3,4,6];
      // Then access it like so. Calling the "new Global("global_urn")" will return the existing global object.
      // Be careful to first add the array property (the top code) and then call it. 
      var globalUrn = new Global("global_urn");
      globalUrn.urnArray,slice(0, 1)