MeMeMax MeMeMax - 1 year ago 107
Javascript Question

Array.filter function in serverside Javascript

I would like to filter an array in my XPage with serverside Javascript. Unfortunately I get the following error:

Error calling method 'filter(Function)' on an object of type 'Array [JavaScript Object]'

I have an Array of Strings like

I call the function like this:



Is there any reason why this error happens? Does this function even exist in ssjs?

This question is not duplicate since it is not clear that Xpages/Lotus Notes runs Rhino in background.

Answer Source

It sounds like whatever server-side JavaScript environment you're using doesn't support ES5 features (that's features from the 5th edition specification from December 2009).

You can use a polyfill for that and other things that were added to Array, see MDN, but beware: If ES5 features aren't supported, it's impossible to add things to Array.prototype without making them enumerable, meaning any code (mis)using for-in to loop through arrays will be affected.

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