Beginner
Add an Item to an Array Using the push Method
Description
In this exercise, you need to write a function that takes an array and a value as input, and adds the value to the end of the array using the push method.
This is a fundamental operation when working with arrays, and understanding how to manipulate arrays is crucial for any developer.
The push method adds one or more elements to the end of an array and returns the new length of the array.
Example usage:
addToArray(['apple', 'banana'], 'cherry'); // Expected output: 3addToArray([], 'first'); // Expected output: 1
Did you know?
The first computer bug was a moth found in a Harvard Mark II computer.
Test Cases
Input:
[ "apple", "banana" ]
Expected Output:
3