开发者

Need to build arrays in Javascript +=?? getting strings

Ok basic JS 101 I know, but can't find the answer...

For the below code I have declared var mls_link = []; In globals

The data.getValue yields a string item (http addresses) When I step through the code the string is an array rather than each "item" being a array entry.. ie mls_link [0] is h (the beginning开发者_运维技巧 of the http address) I want each element to be addressable as an http address so when I ask for mls_link[0] I get 'http://someaddress.com'

for ( var i = 0; i < data.getNumberOfRows(); i++ )
        mls_link+=(data.getValue(i,1)); 

Thanks


In many implementations of Javascript, strings can be indexed like an array (however, as CMS correctly pointed out in the comments, the correct cross-browser way to do this, however, is by using String.charAt). ie:

var s = "hello world";
alert(s[6]); // "w"

If you want to add a value to an array, use Array.push:

mls_link.push(data.getValue(i, 1));


mls_link.push(data.getValue(i,1))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜