Picture of Tobias 1810
Registered 10 years 130 days
Tobias 1810 Wednesday, 3 April 2024, 04:57 PM
array.find and array.includes do not work in JavaScript for App Services

The find() and includes() methods (and maybe more) of Arrays do not work in JavaScript for App Services.

Following code example gives back following error:

var pets = ['cat', 'dog', 'fish'];

log(pets.includes('fish'));

04-03 14:51:56.880 newapp4@dev.t-rust.net JavaScript: Error

TypeError: undefined not callable (property 'includes' of [object Array])

 at [anon] (duk_js_call.c:2919) internal

 at eval (eval:38) preventsyield

Picture of Peter Stock (innovaphone)
Moderator Registered 225 days
Peter Stock (innovaphone) Monday, 22 April 2024, 07:13 AM
1 of 1 users consider this post helpful
Re: array.find and array.includes do not work in JavaScript for App Services
Hi Tobi,

yes. As i mentioned in SDK Developer Talk, the serverside javascript is based on duktape.

Here it may be that some javascript functions you know or find do not work.

In your case, you could do the following instead

function arrayIncludes(array, searchElement) {
for (var element of array) {
if (element === searchElement) {
return true;
}
}
return false;
}

// Sample
var array = [1, 2, 3, 4, 5];
console.log(arrayIncludes(array, 3)); // true
console.log(arrayIncludes(array, 6)); // false

You can test this quite well without searching through any large documentation. If the code runs in the client Javascript and does not work in the server side, it is probably (not 100%, but probably) that the duct tape does not know the function.

Best Regards,

Peter


Andreas Fink
Moderator Registered 12 years 277 days
Andreas Fink (innovaphone) Thursday, 11 April 2024, 10:04 AM in response to Tobias 1810
1 of 1 users consider this post helpful
Re: array.find and array.includes do not work in JavaScript for App Services
Hello Tobias,

the JavaScript Runtime uses Duktape as runtime, so the available JavaScript version is ECMAScript 2015 with some extensions (more information https://duktape.org/guide.html ).

You can also use polyfills to extend the supported subset of functions. An example for usage of such polyfills is available here: https://github.com/innovaphone/jspdfexample

Best Regards
Andreas Fink
← You can define your color theme preference here