.push( obj )移除最後一個元素:
.pop()從 x 元素開始移除 y 個元素:
.splice( x, y )從 x 元素新增 元素:
.splice(x, 0, obj )
example:
var data = {[
{readerid: '100001', name: "吳一英 ", classname: "601"},
{readerid: '100002', name: "吳二英 ", classname: "602"},
{readerid: '100003', name: "吳三英 ", classname: "603"},
{readerid: '100004', name: "吳四英 ", classname: "604"}
]};
data.splice( 2, 0,
{readerid: '100005', name: "吳小英 ", classname: "605"}
);
結果:
var data = {[
{readerid: '100001', name: "吳一英 ", classname: "601"},
{readerid: '100002', name: "吳二英 ", classname: "602"},
{readerid: '100003', name: "吳小英 ", classname: "605"}, {readerid: '100004', name: "吳三英 ", classname: "603"},
{readerid: '100005', name: "吳四英 ", classname: "604"}
]};
若有資料可以對應物件內的資料的話,可以利用 jquery 的語法來快速移除某個元素
var elm_readerid = 'aaa';
data = $.grep( data, function(e) {
return e.readerid != elm_readerid;
});
1 意見:
[Javascript] 新增、移除物件中的元素 >>>>> Download Now
>>>>> Download Full
[Javascript] 新增、移除物件中的元素 >>>>> Download LINK
>>>>> Download Now
[Javascript] 新增、移除物件中的元素 >>>>> Download Full
>>>>> Download LINK 47
張貼留言