Divya Sharma Divya Sharma - 4 months ago 8
jQuery Question

how to call variable or property inside an object in javascript or jquery

I am getting the dates(start and the end dates) dynamically from the servers in json format, so i need to implement in my bootstrap date picker, but its not working here is the code
note: for now i am just implementing my using the variables names

// var start = obj1.start;
// var end = obj1.end;
var start = 01/02/1906;
var end = 01/02/1998;

$('#datepicker').datepicker({
autoclose: true,
startDate: 'start',
endDate: 'end',
});

Answer

The quotes ' or even " around variables will make them only to strings, not a variable reverence. Just remove them the quotes.

But on the other hand, you have to add the quotes on your variable declaration, because these are strings.

// add quotes here
var start = '01/02/1906';
var end = '01/02/1998';

$('#datepicker').datepicker({
    autoclose: true,

    // and remove the quotes here
    startDate: start,
    endDate: end,
});