+ 2
Legth of element on array
Hello, coders. How can i find the length of each element of array? Example : var thisArray = "Cake", "chocolate"; //return 4, 9 ; Thank you in advance.
1 Resposta
+ 12
var arr = ["Cake", "Chocolate"];
var len = new Array();
function getLen(el){
for(i=0; i<el.length; i++)
len.push(el[i].length)
return len.join(",")
}
alert(getLen(arr)) // return 4,9
getLen() returns a string with the length of all your words in the array passed as argument.