Array indexOf() Reference Error?

Hello,
I have these simple code lines and on line 20 I'm getting the error in the comment but I cant find the problem in my code
  var directions      = [0,1,2,3];
  var lockedDirection = 0;
  var lastDirection   = 2; // sample code
  switch (lastDirection) {
  case 0:
       lockedDirection = 2;
       break;
  case 1:
       lockedDirection = 3;
       break;
  case 2:
       lockedDirection = 0;
       break;
  case 3:
       lockedDirection = 1;
       break;
  var a = directions.indexOf(lockedDirection); // ReferenceError: Function directions.indexOf is undefined
  directions.splice(a, 1);

I often add functionality to the built in Javascript objects via their prototype, including indexOf:
* Array.indexOf - Like String.indexOf() but checks for an object in an array
* @method
* @param  {Object} obj object to find in the array
* @returns {Number} location in the array of the object, or -1 if not found
if(!Array.prototype.indexOf) {
    Array.prototype.indexOf = function(obj) {
        for(var i=0; i<this.length; i++) {
            if(obj===this[i]) {
                return i;
        return -1;

Similar Messages

  • Given array control reference, how do I obtain array size programatically

    If an array control reference is passed to a sub-vi, how do I obtain the current length of the array within the sub-vi?  I've tried two properties:  "NumRows", which as documented, contains the visible number of rows in the array control.  "IndexVals" contain the indices of the array element in the upper left corner of the array control.  There seem to be no methods for obtaining the current array length.  I tried changing the class of the array reference to cluster then using the "Controls[]" property... but this generated a runtime error.  What am I missing?  Thanks.
    Solved!
    Go to Solution.

    Taki1999 wrote:
    There's a lot of casting going on in your subvi.
    What is the actual use case?  There might be a way to do this which doesn't require the casting and you could work just with the reference that is passed in.
    For your method you need to wire in a strict class specifier into the To More Specific Class conversion.  I'm not sure how to make the strict class specifier.
    I can help with that but first...
    Working with arrays on unknown data types is no esy task and determining the size is a special challenge and I did just that in this Nugget that talks about using control references. This task is much easier when you know at development time what is in the array. That is where the strict type casting comes into play.
    What I would do...
    1) Make sure the contents of the array is a type def (to support data strcuture changes in the future).
    2) Go to the FP of the VI that has the array in question and drop a generic control ref control.
    3) Ctrl-copy and drag the array in question INTO the the generic ref (still working on the FP). You can tell when you find the "sweet spot" in the ref control because it will switch it appearence. See this mini-nugget for an image where the same thing can be done with que refs.
    4) Make the now strict ref a type def.
    5) Use the type-def'd ref from step #4 in the sub-VI as the proptype used by the "To More Specific...."
    After those changes you should be able to work with array in the sub-VI as if it were in the top level.
    BTW:
    Doing the above on the control in the sub-VI that brings in the ref would allow skipping the "To more Specific..."
    Have fun!
    Ben
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction

  • I get a "JavaScript Application - Reference Error: XPCSafeJSObjectWrapper is not defined" error every time I try to open a new tab.

    <blockquote>Locking duplicate thread.<br>
    Please continue here: [/questions/777191]</blockquote><br>
    Just like the title says, starting with Firefox 4 Beta 6 or 7, I forgot. Any time I try to open a new blank tab (sometimes even when I start up Firefox and the app tabs load) I get an error that says "JavaScript Application - Reference Error: XPCSafeJSObjectWrapper is not defined" If I close it everything works as normal again (until I open a new tab) but it is very annoying to have to do this. Is there any fix for this or is the bug just still there?

    Start Firefox in [[Safe Mode]] to check if one of the add-ons is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Themes).
    * Don't make any changes on the Safe mode start window.
    See:
    * [[Troubleshooting extensions and themes]]
    * [[Troubleshooting plugins]]

  • How can I create an ActiveX IDL to pass an array of references into Labview

    It appears that LV is designed to be able to receive a COM variant that contains an array of references but I cannot understand what the appropriate IDL should be on the COM side of things. I am current trying to use a safearray to hold the references but the automation reference in LV returns a variant that is empty (VT_EMPTY). I have had success with COM interfaces that expose single references, scalers and arrays of scalers and I am able to get the data properly in LV.

    Hi,
    It looks like this is a duplicate post.  The other thread is here, and looks to contain a bit more information.  A response should be posted to this thread soon.
    Thanks.
    Jason W.
    Message Edited by jason_w on 10-18-2007 04:46 PM
    National Instruments
    Applications Engineer

  • Sort Array of References by Label-Name

    I am developing on an DSC application with shared variables and alarming and events with a hugh amount of variables. Each variable is displayed on the front panel within tab controls. To reduce time and effort when expanding the variables I would like to arrange my references from the front panel by the label name. I've attached a part of the intialization of the front panel. There I have to manually expand each variable in the shared variable library, where the name of the variable has to be in the same order as the definition in the cluster.
    My approach was to build an array of references of digital type and sort the references by the label name. Because the shared variables have the same name as the controls they would be in the same order and I also could dislaim the cluster of references.
    maybe somebody can give my an hint.
    Kind Regards,
    Joachim
    Solved!
    Go to Solution.
    Attachments:
    fp.jpg ‏982 KB

    Hi Joachim,
    use the standard "sort an array of cluster" approach!
    Put the control label and the reference (in this order!) in a cluster, make an array of such clusters and sort the array. It will sort by the label and you can unbundle the reference in sorted order...
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome

  • StartTransmit / stopTransmit reference error on NetStream when connecting to device

    Hi all,
    I'm trying to create a P2P connection between a mobile device (Android) and a PC using the NetStream class.
    When the connection is established, the Flash Player Instance on the PC is crashing with a reference error:
    “Property startTransmit not found on flash.net.NetStream”
    I have seen the thread located located here: http://stackoverflow.com/questions/9676496/adobe-cirrus-error-on-direct-connectproperty-st arttransmit-not-found-on-flash-n
    but was not successfull in making it work with my code.
    I have tried extending the NetStream class like so:
    import com.frimastudio.cosy.util.NetConsole;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    public class NetStreamProvider extends NetStream
      public function NetStreamProvider (connection:NetConnection, peerID:String)
       super(connection, peerID);
      // For AIR Android projects: when the device is put to sleep for a moment, this function will be
      // called so we need to implement it to prevent flash from crashing.
      public function startTransmit($p1:*, $p2:*):void
       COSY::console { NetConsole.WarningInternal("NetInterfaceSlot", "startTransmit", "startTransmit called"); }
      public function stopTransmit():void
       COSY::console { NetConsole.WarningInternal("NetInterfaceSlot", "stopTransmit", "stopTransmit called"); }
    and using the NetStreamProvider instead. Without success.
    Any help would be greatly appreciated.
    Thanks.
    Guillaume

    >> i suspect this is AIR-specific (probably if AIR is the sender) -- in my experience it doesn't happen with plain Flash Player.
    [Guillaume] -> Right, it does not happen on NetStreams between 2 Flash Players and 2 AIR app. Only between AIR-FlashPlayer NetStreams. Basically, after a stream is opened between AIR and Flash Player, the AIR is calling "starTransmit" on the FlashPlayer NetStream, wich is not implemented.
    >> try making an object with those method names and assign it to netStream.client
    [Guillaume] -> I tried the following:
    Implement starTransmit/stopTransmit functions in the NetStream.client object
    Implement startTransmit/stopTransmit functions in the NetStream instance (subclassed)
    Without success. Basically, it works fine if I just create a "dummy" client object for the NetStream that has those 2 functions. But If I want to use my own client it was still crashing.
    I found a work around for my problem.
    My NetStream object is sub classed as such:
    public class NetStreamProvider extends NetStream
      public var customClient:Object;
      public function NetStreamProvider (connection:NetConnection, peerID:String)
       super(connection, peerID);
       customClient = new Object();
       this.client = customClient;
       // Implement startTransmit and stopTransmit here for dummy client
       customClient.onPeerConnect = function(subscriber:NetStream): Boolean{
        var subClient:Object=new Object();
        subClient.stopTransmit=function($p1:*,$p2:*):void{
         trace("Cosy: stopTransmit called",$p1,$p2);
        subClient.startTransmit=function():void{
         trace("Cosy: startTransmit called");
        subscriber.client = subClient;
        return true;
      public function SetClient(c:Object):void
       this.client = c;
      public function OnNetStreamAsyncError(event:AsyncErrorEvent):void
    And in the stream status event handler, when the stream is ready (events "NetStream.Play.PublishNotify" and "NetStream.Play.Start") I set the correct client, which has the receive handler. At that point startTransmit was already called:
    And in the stream status event handler, when the stream is ready (events "NetStream.Play.PublishNotify" and "NetStream.Play.Start") I set the correct client, which has the receive handler. At that point startTransmit was already called:
    private function OnNetStreamStatus(e:NetStatusEvent)
    switch(e.info.code)
      case "NetStream.Play.PublishNotify":
               stream = e.target as NetStreamProvider;
               stream.SetupClient(client);
      break;
      case "NetStream.Play.Start":
               stream = e.target as NetStreamProvider;
               stream.SetupClient(client);
      break;
    At this point, i'm not blocked anymore. However, it would be good to know why, when and who are calling those functions to understand the issue. this is not documented anywhere, and might be an issue to a lot of people now that we are starting to see more and more cross-platform connectivity.
    Cheers.
    Guillaume

  • Creating array of references to another array's elements

    I have been coached by NI support to read an array of picture files into an array of picture indicators and then in order to save memory, establish an array of references to the array of picture indicators' elements so that I can use them in a subsequent loop.    Does anyone know a quick way to create this array of references from an array of picture indicators? 
    Solved!
    Go to Solution.

    My understanding is there is only one reference to an array element.  There is no such thing as references to different array elements.
    Why wouldn't you use a reference to the array, use the value property node, then use index array to get out the picture you are interested in?

  • Indexing array of references element by element

    Hello,
    I have a simple question. How do I go about indexing an array of references element by element? For example, when using a cluster reference, there is a property node called "controls [ ]" that we can pass into a for loop. For a normal array, "enable indexing" is usually automatically turned on when entering a for loop. Why is it that for an array of references, this is not the case? Thanks for the help.
    Solved!
    Go to Solution.
    Attachments:
    array_of_references.JPG ‏35 KB

    Since the Get Image is a method, it has to work on something, and that would be a picture control or indicator.  (If you look at the Get Image Method for the array, you'll notice it only returns an image of the front panel object, so I think you'd just get a picture of the array as it looks on the FP).
    So you'd send the picture to an indicator, then use the Get image method on that indicator immediately afterwards.  See attached.  I didn't try this out so I can't be sure it would work, but I think it would.  But it would still be a major hack compared to just using the Picture to Pixmap VI.
    Message Edited by Ravens Fan on 03-27-2009 01:03 AM
    Attachments:
    Array_of_References[1]_BD.png ‏12 KB

  • Dynamic Type Conflect when assigning References error in portal

    Hi Forum,
    We have one ABAP Dynpro Application which runs fine but gives "Dynamic Type conflict when assigning References" error dump after integrating it with Netweaver portal 7 SP12 by creating Webdynpro ABAP iview.
    Please help us to resolve this issue.
    Thanks and Regards
    Sudhir

    hi
    refer this article :
    How to Create Web Dynpro-Based iViews
    http://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/3e36d690-0201-0010-cd99-bfbb81bd33d9
    refer the SAP online help :
    Create a Web Dynpro iView
    http://help.sap.com/saphelp_nw04/helpdata/en/2c/00584289e59041e10000000a1550b0/content.htm
    regards,
    amit

  • When install db 10.2.0.1, report many undefined reference error.

    Hi,
    I try install the db 10.2.0.1 under fc4 linux.
    I select to install software only, but report error:
    Error invoking target 'relink' of makefile
    '/usr/local/oracle/db10g/precomp/lib/ins_precomp.mk' ...
    I check the install/make.log, there are many "undefined reference" error, as following:
    /usr/bin/make -f ins_precomp.mk relink ORACLE_HOME=/usr/local/oracle/db10g EXENAME=proc/Linking /usr/local/oracle/db10g/precomp/lib/proc
    /usr/local/oracle/db10g/lib//libclntsh.so: warning: warning: this program uses gets(), which is unsafe.
    /usr/local/oracle/db10g/precomp/lib/pdc.o(.text+0x236): In function `pdlitlen':
    : undefined reference to `__ctype_b_loc'
    /usr/local/oracle/db10g/precomp/lib/libpgp.a(pgstdf.o)(.text+0x39e): In function `pgswget':
    : undefined reference to `_IO_getc'
    Whether some lib be not found?
    Thanks!

    Keep reading the link log, those are warnings. there is an actual error somewhere.

  • Adding itemCreationPolicy="immediate" on mx:Panel causes null object reference error in Flex 4.x

    The itemCreationPolicy works fine with spark components and other mx component until we hit by mx panel.
    Looks like an error is thrown from StyleProtoChain.
    The interesting thing is the null object reference error both occurs in Flex 4.0 and Flex 4.1, but caused by different objects.
    Is there a workaround to use itemCreationPolicy on mx panel?
    Thank you.

    Yes, there are all kinds of problems when you remove something from the screen that had focus (for instance, at that point you can't capture keyboard events either).
    My code is sprinkled with so many things to make sure something is in focus, I tend to forget that I've done it.
    In your code that changes the currentState, add
    this.setFocus()
    HTH;
    Amy

  • "retrieve disk item references" error

    using the "save PDF to folder as jpg" option below the printer>pdf button , I get a "retrieve disk item references" error, but save PDF to folder as tiff is still working. What is going wrong ??

    You have to get the action and load it into Automator.  It will say it's  from a prvious version.
    Then save the action (this upgrades it to current automator version)
    If you get a folder error change permission on folder so you can save to it
    reboot your computer - mine didn't work until I did this.

  • Thousands of reference errors in TCMRuntimeManager.as

    I'm working on a fairly large AIR app and in the process of trying to find the cause of an out of memory error, I see that the class TCMRuntimeManager.as is throwing thousands of reference errors...just letting my app sit for 10 minutes had over 350,000 reference errors.  The function checkTLFFontsLoaded is the culprit.  I'm not sure if the reference errors are directly related to the out of memory error, but I did notice that as I interact with the app not all the reference errors are getting garbage collected.  If I stop interacting with the app and force garbage collection a few times they all get cleared, but I think that under normal use the garbage collector is getting overwhelmed and doesn't clear out everything, and thus eventually these errors start piling up and contribute to the out of memory error.
    The way the project is built is Flash CS 5.5 is used to import psd files, I set up some linkage classes, then export as a swc.  The psd text fields are imported as TLFTextFields.  The swc assets are then used in a FDT project compiled with Flex SDK 4.5.1 with AIR SDK 3.1.  There are 5 products, each with its own swf.  The swfs are compiled as Flash browser swfs and they are debugged/profiled using the standalone Flash player.  When I profile the individual swfs there are no reference errors.  If I profile the main swf (using adl) without loading the individual swfs, there are no reference errors. It's only when one or more of the product swfs are loaded into the main swf that reference errors start piling up. I've tried conerting the static text fields into bitmaps and registering the fonts (all from the same swc) in each swf and it hasn't made the problem go away but the memory spikes are no longer so dramatic. Any ideas on what is the root cause of this error?

    fl.text.TCMRuntimeManager was implemented by Flash pro. Please forward the question to http://forums.adobe.com/community/flash. Thanks!

  • Reference error: SERVERMODEL_JSP is undefined

    I receive an error message as follows: "While executing in
    insert bar.xml, a javascript error message occurs. The error
    message reads as follows: Reference error: SERVERMODEL_JSP Error
    message occurs when opening Dreamweaver, opening a new page, or
    opening an existing page to modify it. When I click it witht he
    "Enter" key three times, it disappears.
    Please advise.
    Joe Kerenick
    Web Developer

    I would also like to mention that you posted the original message... then barely an hour later made a comment that it was still unanswered.
    In my time zone, you posted at 3:32 AM and then commented at 4:35 AM. I don't know about many people here, but I am fast asleep during that time.
    So please understand we are here to help you, not be your servants to fix your problems.

  • Using an array of references to boolean controls as an input of a subvi to modify propierties from the passed controls.....

    Hello,
    I have a cluster of checkboxes and I want them to be exclusive an to change the visible objects of my vi when I change their state. To keep my code clear I decided to create a subvi that implements this functionality. My subvi recives an array of references to the objects from which I want to change the visibility, an array of references to the checkboxes (to be able change it's values to make them exclusive when one of the checkboxes change it's state), and an array of the values of the checkboxes in the last iteration (to be able to detect which one has change to true and set to false the other ones).
    The problem that I have is that when I use a property node to get the actual values of the checkboxes in the subvi (to compare them to their previus state and detect changes) I obtain a variant type and not a boolean. I've tried to set the mechanical action of the booleans references used as input in the subvi as switch but this doesn't seem to work. I understand that is cause the subvi can't know type of booleans that will recieve and asume the worst case....
    Is there a way to do what I want?
    I hope I've explained myself... Thanks in advance!
    Solved!
    Go to Solution.

    There are a few ways to deal with this, but it would help to see your code. Are you sending a reference of the Cluster into a VI, or individual references of the checkboxes? It sound like you are not using a strict reference. The workaround, since you know the datatype, is to use Variant to Data and change the variant to a boolean, but this shouldn't be necessary. Again, post some code so we can be more help.
    edit: It sounds like you are trying to hard code Radio Buttons. You do know that LabVIEW has Radio Buttons now, right?
    Richard

Maybe you are looking for

  • No pictures show in either the Pictures app or filemanager after 2.0

    I can see the pictures across a USB connection,   but they dont show up on the playbook.  The pictures App is blank with just the wood background,  not even the sample pictures show up.

  • RFC not found error

    Hi people, I have developed a Z RFC in R/3 system and the same is activated and used there. But when I try to use the same RFC in BW system through 'Pattern' function, it gives me as error that the Function Module not found. Do I need to create the s

  • Keynote, Audio file embedded on slide, properties such as file name?

    Any way to see the properties of the embedded audio file such as its name, or where it is located? I've converted from Powerpoint, but miss this RClick, Properties option to at least see the name of the file that is embedded.

  • Can't seem to display the Gui

    I feel dumb but I can't seem to get my Gui to display. I tried everything and this time searched a basic Gui program on the internet. When I compiled it, it did not show up as a separate window as the tutorial said it would. What could possibly be th

  • JNDI and OID schema

    i was able to create a new objectclass the first time but when i ran my code again to create another one, i got the below error. i use the below code to lookup the schema before adding an objectclass. ctx is an initialDirContext object (DirContext)ct