Answers for "how to add functionality inside js object"

0

how to add functionality inside js object

// four variables are created and assigned in a single go,
// separated by commas
var myObj = new Object(),
    str = 'myString',
    rand = Math.random(),
    obj = new Object();

myObj.type              = 'Dot syntax';
myObj['date created']   = 'String with space';
myObj[str]              = 'String value';
myObj[rand]             = 'Random Number';
myObj[obj]              = 'Object';
myObj['']               = 'Even an empty string';

console.log(myObj);
Posted by: Guest on February-18-2021

Code answers related to "how to add functionality inside js object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language