Tuesday 11 June 2019

javascript - Is there a way to remove a whole property from a js object




I presume this is an odd question but I have to ask..



If I have a js object that looks like this:




$scope.obj1 = {
"name":"John",
"number":"Eleven",
"color":"Red"
}


Is there a way to remove an entire property? without re-assigning values to a new object.. So if I want to get rid of "number":"Eleven", I would like the object to look like this...



$scope.obj1 = {

"name":"John",
"color":"Red"
}


Thanks!


Answer



JavaScript has a delete operator:



delete $scope.obj1.number


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...