- Ext JS 3.0 Cookbook
- Jorge Ramon
- 196字
- 2021-04-01 13:43:44
Finding objects in an array and removing array items
The main task in this recipe is to find out whether an arbitrary object exists in an array. A way to remove objects from the array is also explored.
How to do it...
The following steps illustrate how you can perform object existence tests and object removal in an array:
- Create a sample array as follows:
var colorsArray = new Array(); colorsArray[0] = 'Blue'; colorsArray[1] = 'Red'; colorsArray[2] = 'White';
- Determine whether an object exists in an array by trying to find its position in the array:
var position = colorsArray.indexOf('White'); // postition is 2, the index of 'White' in the array. position = colorsArray.indexOf('Brown'); // 'Brown' does not exist in the array, // position is -1.
- Remove one of the objects from the array:
colorsArray.remove('Blue'); position = colorsArray.indexOf('Blue'); // 'Blue' does not exist anymore, // position is -1.
Ext JS augments the native Array
class with Array.indexOf(object)
and Array.remove(object)
. While indexOf(object)
works by examining each array element until it finds one that matches the supplied argument, remove(object)
uses the native Array.splice(index, howmany, element1,....., elementX)
function to remove the supplied argument from the array.
推薦閱讀
- EJB 3.0 Database Persistence with Oracle Fusion Middleware 11g: LITE
- Beginning Swift
- 做合成:Photoshop構圖+透視+紋理+造型+調色技術修煉
- Spring Python 1.1
- Hi!扁平化Photoshop扁平化用戶界面設計教程
- Lightroom Classic完全自學一本通
- Learning VirtualDub: The complete guide to capturing, processing and encoding digital video
- 數字創意大師:Alias二維與三維概念設計工作流淺析
- Getting Started With Oracle SOA Suite 11g R1 – A Hands/On Tutorial
- Photoshop圖形圖像處理實用教程
- Android從入門到精通
- Java EE 6 with GlassFish 3 Application Server
- 中文版Maya 2014基礎培訓教程
- Moodle Course Conversion: Beginner's Guide
- 企業微信公眾平臺開發實戰:再小的個體也有自己的品牌