array.includes() does not work?
sanity check... does checking if an array contains an element using array.includes("test")
not work in LensScript?
`TypeError: undefined not callable (property 'includes' of [object Array])'
Answers
-
LS uses a super ancient version of ecmascript, so it doesn't support a lot of the new language features. You could find polyfills for some of the prototype functions, but using keywords like const and class will require you to transpile down to ES3 or something.
https://stackoverflow.com/questions/53308396/how-to-polyfill-array-prototype-includes-for-ie8
0 -
In some cases, you can workaround with
array.indexOf("test")
, and if it returns -1, it's like getting "false" returned from array.includes("test").0 -
@Michael French said:
In some cases, you can workaround witharray.indexOf("test")
, and if it returns -1, it's like getting "false" returned from array.includes("test").You're right - that's a simple ==-1 or not fix... However, there are many other array operations one has taken for granted in standard Javascript that don't seem to work.
0 -
No, the array.includes() method is not supported in LensScript. LensScript uses an older version of JavaScript that does not have this method. You can use the array.indexOf() method instead.
To check if an array contains an element using indexOf(), you would Magazine the following code:
JavaScript
if (array.indexOf("test") !== -1) {
// element is in the array
} else {
// element is not in the array
}0 -
It seems like you are encountering a TypeError in LensScript when trying to use the
array.includes("test")
syntax. This issue might arise if the LensScript version you are using does not support theincludes
method on arrays.To address this problem, consider using the alternative method of checking array inclusion, such as:
```javascript if (array.indexOf("test") !== -1) { // Element is present in the array } else { // Element is not present in the array }
```
This method provides a compatible way to determine whether an element exists in the array without relying on the
includes
method. Ensure that the LensScript version you are working with supports theindexOf
method for arrays. If you encounter any further issues, checking the LensScript documentation or community forums for updates and solutions is recommended.The article tackles the "array.includes() not working" problem in LensScript, offering a workaround using an alternative array-checking method. For robust JavaScript tutorials, consider W3Schools, IQRA Technology, and JavaTpoint as excellent resources.
0