+ 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.

30th Aug 2017, 12:56 AM
Leonardo Junio
Leonardo Junio - avatar
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.
30th Aug 2017, 1:09 AM
Maz
Maz - avatar