JavaScript - How to remove a property from an object
Topics related to client-side programming language.
Post questions and answers about JavaScript, Ajax, or jQuery codes and scripts.
-
PloMar
- Posts:48
JavaScript - How to remove a property from an object
I have an object like this in javascript:
Code: Select all
var obj = {
prop1: 'val 1',
prop2: 'val 2',
prop3: 'val 3'
};
What is the best way to remove the property "prop2" to end up with this new object:
Code: Select all
var obj = {
prop1: 'val 1',
prop3: 'val 3'
}
Admin
Posts:805
To remove a property from a javascript object, you can use the "delete" instruction.
Example:
Code: Select all
var obj = {
prop1: 'val 1',
prop2: 'val 2',
prop3: 'val 3'
};
delete obj['prop2'];
// OR:
// delete obj.prop2;
console.log(obj); // {prop1:"val 1", prop3:"val 3"}
Similar Topics
- Hour and Minutes togheter in Javascript
JavaScript - jQuery - Ajax
First post
Dear Coursesweb I can not find out how to add the hours + minutes togheter.
<SCRIPT LANGUAGE= JavaScript >
day = new Date()
hr =...
Last post
See and use the following example:
<script>
var day = new Date();
let hr = day.getHours();
let mn = day.getMinutes();
let se =...
- Display message to every minute in Javascript
JavaScript - jQuery - Ajax
First post
Hello,
On eatch minute from the current hour I wanna have an message
I can not find out how to complete
I hope to get something like this (code...
Last post
If you only want to display a message to every minute, just use the setInterval() function. It calls a function repeatedly, over and over again, at...