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
Categories
- All Categories
- Snap AR | Categories
- 2.7K Lens Studio
- 248 Camera Kit
- 30 Spectacles