+ 3
.length() and .length
Whats the difference of .length and .length() in javascript? With an example please
7 ответов
+ 4
Carmen Lucía
.length is array data property where as .length() is a string function.(i am not sure, is it js or not)
So here data property can be used to set and get value of array length where as length function is used to just for calling or getting length of string.
Ex:
Array.length = 5
console.log (Array.length) ;
console.log("string".length()) ; //doubt not exist in js
+ 1
Thanks!
+ 1
You're welcome...
But sry i have a confusion,.. Can you add a Refference for length() function you seen..
It will not working in js. Let me check where about you asking..? Carmen Lucía
I think there is no length() function exists in javascript.....
Both works in Java.
+ 1
It was a homework that said something like:
"Use .length() for this work.
Ex:
var fruits = ["Apple", "Orange"]
The length of this array is 2"
But I think it was a mistake the () and is the normal fruits.length
+ 1
Yes. Both exits in java and works as I said. But in javascript, only field or data property .length exists. And works for arrays and string both..
So there for array : fruits.length returns 2
fruits[0].length returns "Apple" string length; 5
+ 1
Thank you
+ 1
You're welcome...