Hey there,

Why does the function compact not work for me? it is a function according to the javascript documentation.

The problem is, however; if I add the brackets after it, the browser complains for some reason and it says compact is NOT a function. Also, with the function parseInt, it doesn't take brackets after it. Isn't it a function?

I thought functions should always have brackets inserted after thier names like java and php.

  var drinks = ["pepsi", "coke", "juice", null];

  println(drinks.compact);

Thanks.

Recommended Answers

All 10 Replies

it is a function according to the javascript documentation.

According to which documentation?

Which of course is talking about the functions defined in that library and makes no claim about that function being available as part of Javascript itself.

what is compact on arrays then?

I'm using ActiveState komodo and that function,I think, came up.

If it is really a function, then try drinks.compact() instead. Using drinks.compact means you are calling for the value of its local variable named 'compact'.

There's no JS built in method named "compact" in Array object or any other js Object for that matter.
What does it mean anyway?

What should >>array.compact<< do with it, to your understanding ?

If I add brackets after array.compact, then it doesn't work! The komodo IDE says that it returns the array without undefined or null elements.

Is there a good API catalog that I can download and import into my IDE?

I already told you: there is no [].compact method in JavaScript Array Object(s).
And sorry, I don't use "komodo" nor anything of that kind.

Have you at least tried it without brackets?!

If it is really a function

And as I said "If it is really a function" means if the compact() is a function for the object you are calling for. If it is not, it would return undefined instead. By the way, you could implement the function to the object as well. I am not sure what compact() functionality you are looking for.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.