※J.Y Chen 的個人部落格 ※

Just Follow Our Heart And We will shine!

60 瀏覽人次

[Web] 無順序的 Array Object 刪除(delete object in array with No Sequence ID )

Published: (Updated: ) in Web by .

var bookData = [{
    "BookId":1,
    "BookCategory":"資料庫",
    "BookName":"DB2:Maximizing Performance of Online Production Systems",
    "BookAuthor":"W.H.Inmon",
    "BookBoughtDate":"1990-06-18",
    "BookPublisher":"創創公司"
},{
    "BookId":3,
    "BookCategory":"資料庫",
    "BookName":"精通SQL Server 7.0資料庫系統",
    "BookAuthor":"方盈",
    "BookBoughtDate":"1990-06-18",
    "BookPublisher":"零壹"
},
{
    "BookId":2,
    "BookCategory":"資料庫",
    "BookName":"DB2 Answers! Certified Tech Support",
    "BookAuthor":"Richard Yevich",
    "BookBoughtDate":"1990-06-18",
    "BookPublisher":"WESLEY"
}]
var bookDataFromLocalStorage = bookData;

var removeIndex = bookDataFromLocalStorage.map(function(item){
        return item.BookId
    }).indexOf(data.BookId);

bookDataFromLocalStorage.splice(removeIndex , 1);

這樣就大功告成啦!

©2019 - 2024 Henry Chen