博客 / 詳情

返回

JS如何刪除對象中的某一屬性

let math = {
    subject: '數學',
    children: [
        { id: 1, title: '數一' }, 
        { id: 2, title: '數二' }, 
        { id: 3, title: '數三' }, 
        { id: 0, title: '待定' }
    ]
}

// 添加新屬性
math.remark = "備註";
// 刪除對象中某一屬性
delete math.subject

結果:

user avatar zzd41 頭像 shaochuancs 頭像 lesini 頭像 user_p5fejtxs 頭像 lidalei 頭像 gfeteam 頭像 tofrankie 頭像 fyuanlove 頭像 heptagon 頭像 dashan_5c230d1ae1f9e 頭像 jidongdemogu 頭像 harryfyodor 頭像
52 位用戶收藏了這個故事!

發佈 評論

Some HTML is okay.