var a = {
  one : 1,
  arr : ['one','two','three'],
  doThis : function(){return 20;},
  two : 2
};

var html = 'a.one = ' + a.one + '<br/>';
html += 'a.arr[0] = ' + a.arr[0] + '<br/>';
html += 'a.doThis() = ' + a.doThis() + '<br/>';
html += 'a.two = ' + a.two;
html += 'a.one + a.arr[0] + a.doThis() + a.two = ' + a.one + a.arr[0] + a.doThis() + a.two + '<br/>';

var no = parseInt(a.one);
var no1 = parseInt(a.doThis());
var no2 = parseInt(a.two);

html += 'a.one + a.arr[0] + a.two = ' + no + no1 + no2 + '<br/>';
document.getElementById('content').innerHTML = html;
​

OUTPUT:

a.one = 1
a.arr[0] = one
a.doThis() = 20
a.two = 2a.one + a.arr[0] + a.doThis() + a.two = 1one202
a.one + a.arr[0] + a.two = 1202

I wish to add the first, third and the fourth numbers so that the answer is 23 ....
But all I do I concatenation .... i.e. 1202

Please help !

var total=no+no1+no2;
html += 'a.one + a.arr[0] + a.two = ' + total + '<br/>';
document.getElementById('content').innerHTML = html;
​
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.