deepak asai deepak asai -3 years ago 85
HTML Question

How to use an variable inside object declaration in javascript

Am running this code in javascript..

function addEventToCalendar(date1, email){

var date = date1+'T00:30:00.000Z';
var event = {
'summary': 'Event try1',
'dateTime': date,
}
}


I am obtaining a function parameter and using it for creating a variable called
date . when i try to use that variable inside the object called event.. But when i do that, the variable is getting read as

'dateTime': ' 2017-02-22T00:30:00.000Z'


with space at the beginning. Because of this am not able to proceed further. How to avoid this

Answer Source

Try using date.trim();. This should remove the leading space.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download