Unsupported JavaScript functions and alternatives
This topic describes the JavaScript functions that are not supported in Sitecore CDP and the alternative functions you can use instead.
The following JavaScript entities are not supported in Sitecore CDP and we do not provide alternative examples:
-
asyncfunctions -
generatorfunctions -
map primitivefunctions -
promiseobjects -
set
primitivedata types -
supportsymbols as unique identifiers -
weakmapdata structure -
weaksetdata structure -
optional chaining operator (
?.) -
nullish coalescing operator (
??)
Array.entries
Sitecore CDP does not support the Array.entries function. Use the following JavaScript to return a new array iterator object that enables you to iterate through the key/value pairs in the array.
Array.find
Sitecore CDP does not support the Array.find function. As an alternative, you can use the following JavaScript to check for each element present in the array. If the code finds an array element with a true value, it returns the value of that array element.
Array.findIndex
Sitecore CDP does not support the Array.findIndex function. As an alternative, you can use the following JavaScript to check for an array element that returns a true value. If the code finds an array element with a true value, it returns the index of that array element. It does not check the remaining values.
Array.flat
Use the following JavaScript to take a multidimensional array and turn it into a single dimensional array. You can use reduce or spread in certain scenarios or a decomposition syntax, as shown in the code sample. Sitecore CDP does not support the Array.flat function.
Array.flatMap
Use the following JavaScript to flatten the input array element into a new array. You can use reduce in certain scenarios, as shown in the code sample. Sitecore CDP does not support the Array.flatMap function.
Array.includes
Use the following JavaScript to determine whether an array contains a specified element. The code returns true if the array contains the element, and false if not. Sitecore CDP does not support the Array.includes function.
Array.keys
Use the following JavaScript to return the keys or a subset of the keys of an array. Sitecore CDP does not support the Array_keys function.
Array.of
Use the following JavaScript to use the slice method of an array and apply it toward an object using call. Sitecore CDP does not support the Array.of function.
Array.values
Use the following JavaScript to return all the elements of the array. Sitecore CDP does not support the Array.values function.
For...of
Use the following JavaScript to iterate over iterable objects. Sitecore CDP does not support the for...of statement.
Object.assign
Use the following JavaScript to copy the values from one or more source objects to a target object. Sitecore CDP does not support the Object.assign function.
Object.entries
Use the following JavaScript to return an array of a given object's own enumerable string-keyed property [key, value] pairs, in the same order as provided, regardless of how an object is defined. Sitecore CDP does not support the Object.entries function.
Object.js
Use the following JavaScript to determine whether two values are the same. Sitecore CDP does not support the Object.js function.
Object.values
Use the following JavaScript to return the array of the given object's enumerable property values. Sitecore CDP does not support the Object.values function.