-
9 Dec 2011 1:37 PM #1
Answered: Array contains value
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?
Thanks in advanceCode:if (!Ext.Array.contains(myapp.views.nearMe.plottedMuseums, museum)){ museumsToPlot.push(museum); myapp.views.nearMe.plottedMuseums.push(museum) }
L
-
Best Answer Posted by mitchellsimoens
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
-
10 Dec 2011 7:02 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
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 @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.


Reply With Quote