Need to build arrays in Javascript +=?? getting strings – Education Career Blog

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_link0 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(s6); // "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))

Leave a Comment