Answers for "add property to object javascript"

39

remove property from object JS

var person = {"first_name": "Billy","last_name": "Johnson"};
delete person.last_name; //delete last_name property
Posted by: Guest on July-19-2019
14

how to add property to object in javascript

var data = {
    'PropertyA': 1,
    'PropertyB': 2,
    'PropertyC': 3
};

data["PropertyD"] = 4;

// dialog box with 4 in it
alert(data.PropertyD);
alert(data["PropertyD"]);
Posted by: Guest on April-16-2020
2

add property to object javascript

let yourObject = {};

//Examples:
//Example 1
let yourKeyVariable = "yourKey";
yourObject[yourKeyVariable] = "yourValue";

//Example 2
yourObject["yourKey"] = "yourValue";

//Example 3
yourObject.yourKey = "yourValue";
Posted by: Guest on September-28-2020
3

how to a property from a JavaScript object

delete myObject.regex;
// or,
delete myObject['regex'];
// or,
var prop = "regex";
delete myObject[prop];


/** Demo */
var myObject = {
    "ircEvent": "PRIVMSG",
    "method": "newURI",
    "regex": "^http://.*"
};
delete myObject.regex;

console.log(myObject);
Posted by: Guest on November-27-2019
2

Add New Properties to a JavaScript Object

var myDog = {
  "name": "Happy Coder",
  "legs": 4,
  "tails": 1,
  "friends": ["freeCodeCamp Campers"]
};

myDog.bark = "woof";
// or
myDog["bark"] = "woof";
Posted by: Guest on July-19-2020
0

add property with value in js

var myObject = {
    sProp: 'some string value',
    numProp: 2,
    bProp: false
};
Posted by: Guest on October-23-2020

Code answers related to "add property to object javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language