Bagaimana menghapus properti dari objek
Belajar bagaimana menghapus properti dari objek JavaScript.
Menghapus properti dari objek
delete
Operator dapat menghapus properti dari objek:
Instance
var person = { firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue" }; delete person.age; // atau delete person["age"]; // Sebelum dihapus: person.age = 50, setelah dihapus, person.age = undefined
delete
Operator ini akan menghapus nilai properti serta properti itu sendiri.
Setelah dihapus, properti ini tidak dapat digunakan sebelum ditambahkan kembali.
delete
Operator untuk digunakan dalam properti objek. Ini tidak mempengaruhi variabel atau fungsi.
Perhatian:delete
Operator tidak boleh digunakan untuk properti objek JavaScript yang diatur sebelumnya. Ini mungkin akan membuat aplikasi Anda runtuh.