Array length in Javascript chrome error -
i have strange problem js console in chrome, if go in chrome console , write :
var numero = new array(["/php/.svn/tmp", "/php/.svn/props"]);
return me "undefined" think numero array 2 elements, if write:
numero
returns:
[array[2]]
after
numero.length
and return 1 ..... why? don't return 2 ??? doing wrong? can give method returns 2? in advance
edit: explain problem. have function return when selected 2 items :
myfolders.getselected() ["/php/.svn", "/php/upload.php"]
and when selected 1 items:
myfolders.getselected() "/php/upload.php"
as u note second 1 isn't array.
now use method activate on change selected item calculate global variable:
function calcolonumeroelementi(){ var numero = new array(myfolders.getselected()); numeroelementiselezionati = numero[0].length; }
but returns 1 or number of characters when selected 1 items.
don't use new array, use literal notation:
var numero = ["/php/.svn/tmp", "/php/.svn/props"];
update (based on comments)
if have function myfolders.getselected()
returns single string , want add array, can either declaratively:
var numero = [myfolders.getselected()]
or, if plan add multiple values, e.g. in loop, can push new value array
var numero = []; ... numero.push(myfolders.getselected());
Comments
Post a Comment