Skip to main content


Returns : Array

Converts selector text, an Array of objects or selector text, a NodeList, an object, or almost any Array-like object (like a jQuery result) into a flat Array. You can optionally define a scope (added in 3.7.0) for the selector text which limits results to descendants of that scope Element, similar to jQuery.find()

// these all return the corresponding elements wrapped in a flat Array:

// selector text (returns the raw elements wrapped in an Array)
let targets = gsap.utils.toArray(".class");

// raw element/object
let targets = gsap.utils.toArray(myElement);

// jQuery (or other Array-like) object
let targets = gsap.utils.toArray($(".class"));

// Array of selector text (same result as ".class1, .class2")
let targets = gsap.utils.toArray([".class1", ".class2"]);

// Only descendant elements of myElement
let targets = gsap.utils.toArray(".class", myElement);


  1. targets : [Object | String | NodeList | Array] - The target(s) that you want wrapped in a flattened Array (it can be selector text, objects, NodeList, jQuery objects, etc.)
  2. scope : [Element | Ref] (optional) - The Element (or React ref) to which the selector text scope should be limited, like calling .querySelectorAll([selector-text]) on this Element rather than the document. In other words, it will only return descendant Elements of the scope Element, like jQuery.find(). This is only helpful when targets is selector text.