user1170330 user1170330 - 1 year ago 74
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("another test");

return arr;

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

Here is a fiddle.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download