I have this object:
object = {
key:["1","2","3","4"开发者_StackOverflow,"5"],
key2:["5","7","8","9"]
}
How do I delete an object key and how to delete an object key value ?
For deleteing a property from an object you can use
delete object.key
For deleting an item from the array, you could use many methods, one of which is to make use of jQuery's grep
method:
// removes "5" from the values
object.key2 = $.grep(object.key2,function(x) { return x != "5"});
Live examples: http://jsfiddle.net/rbREb/
How do I delete an object key and how to delete an object key value ?
Use the delete
operator to remove a property from an Object
.
delete object.key
Removing the property will remove its associated value (or at least mark it for garbage collection).
you can use delete object[key]. This will delete both the key and value
精彩评论