Please enable javascript Mega Explorer

The Ultimate Testing Machine for Javascript Array functions


Transformers & Analysers: map(), forEach(), filter(), reduce()

array1:


array2:




Example 1: array2 = array1.map(function(x) { return x * input; });



Example 2: array1.forEach(function(x, index) { array2[index] = x * input; });



Example 3: array2 = array.filter(function(x) { return x > input; });



Example 4: array2 = array.reduce(function(accumulator, currentValue) { return accumulator + currentValue;}, input); });

Adders & Deleters: push(), pop(), shift(), unshift()

array1:


array2:




Example 1: array1.push(input);



Example 2: array1.pop(); No input needed.



Example 3: array1.unshift(input);



Example 4: array1.shift(); No input needed.



The Disectors & Inserters: slice(), splice(), concat()

array1:


array2:




Example 1: array2 = array1.slice(startIndex, endIndex);



Example 2: array1.splice(startIndex, numberOfElementsToDelete, elementToAdd);

Example 3: array2 = array1.concat(array2); Note: Slice an array from array1 to array2 first.



The Finders: indexOf(), lastIndexOf(), find(), findIndex()

array1:


array2:




Example 1: array2 = array1.indexOf(input);



Example 2: array2 = array1.lastIndexOf(input);



Example 3: array2 = array1.find(function(x) { return x > input; });



Example 4: array2 = array1.findIndex(function(x) { return x > input; });



The Boolean Testers: includes(), every(), some()

array1:


array2:




Example 1: array2 = array1.includes(input);



Example 2: array2 = array1.every(function(x) { return x > input; } );



Example 3: array2 = array1.some(function(x) { return x > input; } );



The Converters: join(), toString(), Array.from()

array1:


array2:




Example 1: array2 = array1.join("input"); Note: You may use string.split() to convert the string back into an array.



Example 2: array2 = array1.toString(); No input needed



Example 3: array2 = Array.from(array1); array2.push(input);



Example 4: array2 = array1; array2.push(input);

Note: This is to show you the difference if you did not use the previous function to save the data from array1.