What is the difference between the two?
So I know that array.size()
is a function while array.length
is a property. Is there a usecase for using one over the other? Is one more efficient? (I would imagine .length
to be significantly faster as it is a property rather then a method call?) Why would one ever use the slower option? Are there some browsers that are incompatible with one or the other?
var x = [];
console.log(x.size());
console.log(x.length);
console.log(x.size()==x.length);
x =[1,2,3];
console.log(x.size());
console.log(x.length);
console.log(x.size()==x.length);
Will print:
0, 0, true
3, 3, true
Array.size()
method in native JavaScript? – VisioN Jan 7 '13 at 19:23.size
... – 0x499602D2 Jan 7 '13 at 19:24.size()
is likely from Prototype framework: prototypejs.org/doc/latest/language/Array/prototype/size – MikeM Jan 7 '13 at 19:30