Array Methods
Array prototype methods and statics in SSJS — which work natively, which are partial, and which are missing, with safe ES3/ES5 alternatives and polyfill links.
Each member below is tagged with the ECMAScript edition that standardized it: (ES3), (ES5), or (ES6). Methods that need a polyfill link to Polyfills.
Status legend
| Icon | Meaning |
|---|---|
| ✅ Works | Available and behaves as expected |
| ⚠️ Partial | Available but with a documented caveat or bug |
| ❌ Missing | Not available — use the workaround / polyfill |
Members
| Member | ES | Status | Notes |
|---|---|---|---|
push(...items) |
ES3 | ✅ Works | |
pop() |
ES3 | ✅ Works | |
shift() |
ES3 | ✅ Works | |
unshift(...items) |
ES3 | ✅ Works | |
concat(...arrays) |
ES3 | ✅ Works | |
join(separator) |
ES3 | ✅ Works | |
reverse() |
ES3 | ✅ Works | |
length |
ES3 | ✅ Works | |
toLocaleString() |
ES3 | ✅ Works | |
slice(start, end) |
ES3 | ⚠️ Partial | Negative indices unreliable — see Polyfills |
sort(compareFn) |
ES3 | ⚠️ Partial | Comparator behavior unreliable — see Polyfills |
splice(start, deleteCount, ...items) |
ES3 | ⚠️ Partial | Delete form works; insert form (3rd+ arg) ignores start/deleteCount — see Polyfills |
indexOf(searchValue, fromIndex) |
ES5 | ❌ Missing | See Polyfills |
lastIndexOf(searchValue, fromIndex) |
ES5 | ⚠️ Partial | Broken — always returns -1; see Polyfills |
forEach(fn) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
map(fn) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
filter(fn) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
reduce(fn, initial) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
reduceRight(fn, initial) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
some(fn) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
every(fn) |
ES5 | ❌ Missing | Use a for loop or the polyfill |
find(fn) |
ES6 | ❌ Missing | Use a for loop or the polyfill |
findIndex(fn) |
ES6 | ❌ Missing | Use a for loop or the polyfill |
includes(searchValue) |
ES6 | ❌ Missing | Use indexOf(x) !== -1 or the polyfill |
fill(value, start, end) |
ES6 | ❌ Missing | See Polyfills |
copyWithin(target, start, count) |
ES6 | ❌ Missing | See Polyfills |
entries() |
ES6 | ❌ Missing | See Polyfills |
keys() |
ES6 | ❌ Missing | Use a standard index for loop |
values() |
ES6 | ❌ Missing | Use a standard index for loop |
at(index) |
ES6 | ❌ Missing | Use arr[i] (and arr[arr.length + i] for negative i) |
flat(depth) |
ES6 | ❌ Missing | Concatenate nested arrays manually in a loop |
flatMap(fn) |
ES6 | ❌ Missing | Build the result with a for loop and push |
findLast(fn) |
ES6 | ❌ Missing | Iterate from the end with a for loop |
Array.isArray(value) |
ES5 | ❌ Missing | See Polyfills |
Array.of(...items) |
ES6 | ❌ Missing | See Polyfills |
Array.from(source) |
ES6 | ❌ Missing | Build the array with a for loop over the source |
push
(ES3) — ✅ Works. Appends one or more items to the end of the array and returns the new length.
var arr = [1, 2, 3];
arr.push(4); // [1, 2, 3, 4]
pop
(ES3) — ✅ Works. Removes and returns the last item.
var arr = [1, 2, 3];
var last = arr.pop(); // 3, arr = [1, 2]
shift
(ES3) — ✅ Works. Removes and returns the first item.
var arr = [1, 2, 3];
var first = arr.shift(); // 1, arr = [2, 3]
unshift
(ES3) — ✅ Works. Prepends one or more items and returns the new length.
var arr = [1, 2, 3];
arr.unshift(0); // arr = [0, 1, 2, 3]
concat
(ES3) — ✅ Works. Returns a new array combining the array with the given arrays/values.
var combined = [1, 2].concat([3, 4]); // [1, 2, 3, 4]
join
(ES3) — ✅ Works. Joins all elements into a string using the given separator.
["Hello", "World"].join(", "); // "Hello, World"
reverse
(ES3) — ✅ Works. Reverses the array in place.
var arr = [1, 2, 3];
arr.reverse(); // [3, 2, 1]
length
(ES3) — ✅ Works. The number of elements in the array.
[1, 2, 3].length; // 3
toLocaleString
(ES3) — ✅ Works. Returns a locale-specific string representation.
[1, 2, 3].toLocaleString(); // "1,2,3"
slice
(ES3) — ⚠️ Partial. Returns a shallow copy of a portion of the array. Negative indices are unreliable in SFMC; apply the polyfill for full ES5 behavior.
var arr = [0, 1, 2, 3, 4];
arr.slice(1, 3); // [1, 2]
arr.slice(); // copy of arr
// arr.slice(-2) — negative indices unreliable; use the polyfill
sort
(ES3) — ⚠️ Partial. Sorts in place. The comparator behavior is unreliable in SFMC; apply the polyfill for predictable results.
var arr = [3, 1, 4, 1, 5];
arr.sort(function (a, b) { return a - b; }); // ascending
splice
(ES3) — ⚠️ Partial. Signature: splice(start[, deleteCount[, item1[, ...itemN]]]).
The delete-only form — splice(start) and splice(start, deleteCount) — works correctly. The bug surfaces only when you insert items: as soon as a third argument is passed, the engine ignores start and deleteCount and overwrites from the left. Apply the polyfill from Polyfills if you use the insert form.
// Delete-only form works natively:
var arr = ["a", "b", "c", "d"];
arr.splice(1, 1); // ["a", "c", "d"]
arr.splice(2); // ["a", "c"]
// Insert form REQUIRES the polyfill:
var arr2 = ["a", "b", "c", "d"];
arr2.splice(1, 1, "X"); // ["a", "X", "c", "d"]
arr2.splice(1, 0, "B", "C"); // insert without removing
indexOf
(ES5) — ❌ Missing. Not available in SFMC. Apply the polyfill, or scan with a for loop.
function indexOf(arr, value) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === value) { return i; }
}
return -1;
}
lastIndexOf
(ES5) — ⚠️ Partial. Present but broken — always returns -1. Apply the polyfill, or scan from the end with a for loop.
function lastIndexOf(arr, value) {
for (var i = arr.length - 1; i >= 0; i--) {
if (arr[i] === value) { return i; }
}
return -1;
}
forEach
(ES5) — ❌ Missing. Use a for loop or the polyfill.
for (var i = 0; i < arr.length; i++) {
var item = arr[i];
// process item
}
map
(ES5) — ❌ Missing. Use a for loop or the polyfill.
var doubled = [];
for (var i = 0; i < arr.length; i++) {
doubled.push(arr[i] * 2);
}
filter
(ES5) — ❌ Missing. Use a for loop or the polyfill.
var evens = [];
for (var i = 0; i < arr.length; i++) {
if (arr[i] % 2 === 0) { evens.push(arr[i]); }
}
reduce
(ES5) — ❌ Missing. Use a for loop or the polyfill.
var sum = 0;
for (var i = 0; i < arr.length; i++) {
sum += arr[i];
}
reduceRight
(ES5) — ❌ Missing. Use a reverse for loop or the polyfill.
var sum = 0;
for (var i = arr.length - 1; i >= 0; i--) {
sum += arr[i];
}
some
(ES5) — ❌ Missing. Use a for loop or the polyfill.
var hasLarge = false;
for (var i = 0; i < arr.length; i++) {
if (arr[i] > 10) { hasLarge = true; break; }
}
every
(ES5) — ❌ Missing. Use a for loop or the polyfill.
var allLarge = true;
for (var i = 0; i < arr.length; i++) {
if (arr[i] <= 10) { allLarge = false; break; }
}
find
(ES6) — ❌ Missing. Use a for loop or the polyfill.
var found = null;
for (var i = 0; i < arr.length; i++) {
if (arr[i].id === targetId) { found = arr[i]; break; }
}
findIndex
(ES6) — ❌ Missing. Use a for loop or the polyfill.
var idx = -1;
for (var i = 0; i < arr.length; i++) {
if (arr[i].id === targetId) { idx = i; break; }
}
includes
(ES6) — ❌ Missing. Use the polyfilled indexOf (indexOf(x) !== -1) or the polyfill.
function includes(arr, value) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === value) { return true; }
}
return false;
}
fill
(ES6) — ❌ Missing. Apply the polyfill, or assign in a loop.
var arr = [];
for (var i = 0; i < 5; i++) { arr.push(0); } // [0,0,0,0,0]
copyWithin
(ES6) — ❌ Missing. Apply the polyfill.
entries
(ES6) — ❌ Missing. Apply the polyfill, or iterate with an index for loop reading i and arr[i].
keys
(ES6) — ❌ Missing. Use a standard index for loop (for (var i = 0; i < arr.length; i++)).
values
(ES6) — ❌ Missing. Use a standard index for loop reading arr[i].
at
(ES6) — ❌ Missing. Use arr[i], and arr[arr.length + i] for negative i.
var arr = [10, 20, 30];
arr[0]; // 10 (arr.at(0))
arr[arr.length - 1]; // 30 (arr.at(-1))
flat
(ES6) — ❌ Missing. Concatenate nested arrays manually in a loop.
function flatten(arr) {
var result = [];
for (var i = 0; i < arr.length; i++) {
if (typeof arr[i] === "object" && arr[i].length !== undefined) {
for (var j = 0; j < arr[i].length; j++) { result.push(arr[i][j]); }
} else {
result.push(arr[i]);
}
}
return result;
}
flatMap
(ES6) — ❌ Missing. Build the result with a for loop and push.
var result = [];
for (var i = 0; i < arr.length; i++) {
var mapped = transform(arr[i]); // returns an array
for (var j = 0; j < mapped.length; j++) { result.push(mapped[j]); }
}
findLast
(ES6) — ❌ Missing. Iterate from the end with a for loop.
var found = null;
for (var i = arr.length - 1; i >= 0; i--) {
if (predicate(arr[i])) { found = arr[i]; break; }
}
Array.isArray
(ES5) — ❌ Missing. Apply the polyfill.
function isArray(value) {
return Object.prototype.toString.call(value) === "[object Array]";
}
Array.of
(ES6) — ❌ Missing. Apply the polyfill, or build an array literal directly.
Array.from
(ES6) — ❌ Missing. Build the array with a for loop over the source.
var arr = [];
for (var i = 0; i < source.length; i++) { arr.push(source[i]); }