top of page
Search

Our Modern Javascript method for today is, includes(). This is really useful in lots of use-cases in Adobe After Effects.

  • Writer: Roland Kahlenberg
    Roland Kahlenberg
  • Apr 10
  • 2 min read

 

The includes() method can be used to check for a value/element in a Text String or an array. It is inherently a conditional, much like the if...else conditional but it's much shorter to write, it's more readable and, hence, easier to understand when crafting complex relationships across different data structures.



 

Syntax:

string.includes(value) or array.includes(substring)


The includes() method checks if a specific value exists in an array or string, returning true if it does and false if it doesn’t.


It’s case-sensitive for strings and performs a strict equality check (===) for arrays, making it straightforward and intuitive.


In After Effects, includes() shines for tasks like validating inputs, filtering data, or triggering effects based on content—think of it as a quick “is this here?” test without looping.



 

The includes() method is ideal when having to deal with spreadsheet/data-driven content or when you have to craft Text Strings dynamically – this is a common practice when developing hyper-personalized or geographical-sensitive videos where the displayed text differs based on which value(s) in the dataset is related to the current layer or composition or to another part of the dataset.


So, you may check if a video/composition/layer is intended for individuals living in a specific geographical region and then choose to display a specific flag, statistic or to dynamically craft a sentence based on a combination of fixed texts and variable/data-driven text strings.



The includes() method was used in this animation to check if a layer's name included a specific team name and a specific color. The result was then used to affect Opacity and Color.

 


The Expression below checks if a layer's name includes the word "Winner".


// Start of Expression. Name/Rename your Text Layer to test different layer names and includes() test. // Apply this Expression to text.sourceText Property - checks if a specific word appears in a Text String


// Get this layer's name

var mySourceText = thisLayer.name;


// Combine includes() and Ternary Conditional to display appropriate text.

mySourceText.includes("Winner") ? "We Have a Winner" : "No Winner"



/*

In this expression, we check if "Winner" is a substring of thisLayer.name.


includes() returns true for names like "Winner01" or "aWinner" and false for "Winger". So, take note this includes() isn't about an exact match as it provides for an allowance for leading and trailing characters.


*/


// End of Expression




 



Here's an example of chaining includes() to check for two conditions -




// Start of Expression


// Apply this Expression to the Opacity Property.

// We chain the includes() method to check for two conditions.



var myTeamName = thisLayer.name;

var myTeamColor = thisLayer.name;


// We test if this layer's name includes the words TeamA and Red and set their opacity values accordingly.

myTeamName.includes("TeamA") && myTeamColor.includes("Red") ? 100 : 50;



// End of Expression




 


Without using includes(), how would you have achieved the results of the sample expressions above?




 



Related URLs:


includes():


Ternary Conditional:

 
 
 

Comentarios


bottom of page