Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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"]);
Comment

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";
Comment

add property with value in js

var myObject = {
    sProp: 'some string value',
    numProp: 2,
    bProp: false
};
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript anagram 
Javascript :: file upload in jquery 
Javascript :: javascript set variable if not defined 
Javascript :: modal.hide not working 
Javascript :: axios get with headers 
Javascript :: concat js mdn 
Javascript :: round number 2 decimals javascript 
Javascript :: duplicate numbers in an array javascript 
Javascript :: discord js bot embed user profile picture 
Javascript :: find highest value in array javascript 
Javascript :: switch in react 
Javascript :: mongoose update and return new 
Javascript :: chrome.storage.local get 
Javascript :: js regex replace multiple matches 
Javascript :: check if string matches a regex 
Javascript :: stop page refresh on button click react 
Javascript :: how to add youtube videos to react app 
Javascript :: conditional style prop react 
Javascript :: how to access curl data in javascript 
Javascript :: js check if two arrays contain same values 
Javascript :: merge array of objects javascript 
Javascript :: add on click to div using jquery 
Javascript :: light font color to dark background using javascript 
Javascript :: make input not editable for user js 
Javascript :: javascript loop object 
Javascript :: Capitalize the first letter of string using JavaScript 
Javascript :: Pass object to query on Router.push NextJs 
Javascript :: regex find first instace 
Javascript :: npm run js file from command line 
Javascript :: how to normalize string in javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =