Copy link to clipboard
Copied
Hello guys
I was wondering how to check if a specific char is contained in the layer name.
Tried .contains("_") and .include("_") but neither worked...
Does anyone know the Answer to this question?
Thanks a lot
Hey, try with indexOf:
'My_Layer'.indexOf('_') > -1; // returns true
'MyLayer'.indexOf('_') > -1; // returns false
Copy link to clipboard
Copied
Hey, try with indexOf:
'My_Layer'.indexOf('_') > -1; // returns true
'MyLayer'.indexOf('_') > -1; // returns false
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Or may be you can try match:
'My_Layer'.match('_') != null
Best
Sunil
Copy link to clipboard
Copied
.match() uses a regular expression (even if your example contains a literal), and creates an array -- which is expensive. If you have to use a regular expression to test whether a string contains a substring, .test() is quicker because it doesn't create an array, it returns a boolean.
P.
Copy link to clipboard
Copied
Thank you for explaining, .test() is also new for me.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now