How do I use an array variable in a load rule?

This article describes how to use an array variable in a load rule.

Question

Can I use an array variable in a load rule with a condition such as CONTAINS?

Answer

Yes.

The JavaScript code generated by load Rule conditions uses the toString() method, which will convert an array to a comma-delimited string. A load rule that uses the CONTAINS condition, for example, will convert the variable to a string using toString(), then use indexOf() to find the desired value within the variable.

> product_name = ["Nexus One", "Samsung Razor", "Apple iPhone"]
["Nexus One", "Samsung Razor", "Apple iPhone"]

> product_name.toString()
"Nexus One,Samsung Razor,Apple iPhone"

> product_name.toString().indexOf("Apple")
24

Was this page helpful?

This page was last updated: January 7, 2023