user1170330 user1170330 - 7 months ago 11
Javascript Question

Work with returned array from function

I'm trying to return an array from a function and work with its results.

When I just want to get its length, I always get a 0:

function myFunc() {
var arr = [];

arr.push("test");
arr.push("another test");

return arr;
}

alert(myFunc.length) // expected 2, but got 0


Here is a fiddle.

Answer

You need to call it as myfunc().length because you are calling a function.