- 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.
推薦閱讀
- 3ds Max 2014標準教程(全視頻微課版)
- Oracle SOA Suite Developer's Guide
- Photoshop CC超級學習手冊
- Solid Works 2021產品設計標準教程
- CorelDRAW服裝設計實用教程(第四版)
- AI繪畫:Stable Diffusion從入門到精通
- PHP應用開發與實踐
- After Effects影視特效立體化教程:After Effects 2021(微課版)
- Oracle Enterprise Manager Grid Control 11g R1: Business Service Management
- Apache Solr 3.1 Cookbook
- Microsoft Azure: Enterprise Application Development
- 修片有道:PHOTOSHOP攝影后期專業技法
- Oracle Web Services Manager
- 攝影師的后期課:Lightroom后期技法篇
- Apache Solr High Performance