Results 1 to 2 of 2

Thread: Array contains value

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default Answered: Array contains value

    Fairly new to Sencha Touch and Javascript in general, so please be gentle

    What is the best way to search an array for existence of a value? I see that there is an Ext.Array helper class, with .contains, .filter, etc (lots of useful methods). However, when I try to use it, I'm getting Ext.Array is null. When I inspect in Chrome, I can see that, in fact, the Ext object does not have an Array property (each, etc etc are there). Is there some additional dependency? Or is Array only available in the "full" Ext? Or is there a better way to do this?

    Code:
    if (!Ext.Array.contains(myapp.views.nearMe.plottedMuseums, museum)){
       museumsToPlot.push(museum);
       myapp.views.nearMe.plottedMuseums.push(museum)
    }
    Thanks in advance

    L

  2. There is no Ext.Array. In Sencha Touch 1 we put those convenient methods onto the Array.prototype meaning you can do

    Code:
    var arr = [1, 2, 3, 4, 5];
    arr.contains(2); //true
    arr.indexOf(3); //2

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1390
      0  

    Default

    There is no Ext.Array. In Sencha Touch 1 we put those convenient methods onto the Array.prototype meaning you can do

    Code:
    var arr = [1, 2, 3, 4, 5];
    arr.contains(2); //true
    arr.indexOf(3); //2
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •