2024年4月2日 星期二

jQuery.grep() 用法

 目的:   jQuery.grep() 用法

處理說明:1>grep可以在陣列中逐一尋找並篩選出符合條件的內容,
                        該方法會返回一個新的陣列。

                    2> jQuery.grep( array, function(elementOfArray, indexInArray) [, invert ] )

範例1:從陣列中移除 9 的 item
           var arr = [ 1, 9, 4, 7, 3, 8, 6, 9, 1 ]; //找出數值不等於9的資料 
           arr = jQuery.grep(arr, function( item ) 
                    { return item !== 9; });
           結果  :
                        [1, 4, 7, 3, 8, 6, 1]

範例2: 從陣列中移除 PK 的 item
            CHK_PK_OBJ.PK_LIST = jQuery.grep(CHK_PK_OBJ.PK_LIST, function (item) {
return item != Tmp_PK;
});

沒有留言:

張貼留言