Modify the function to push the given item onto the end of the array and return the array.
function addItemToArray(array, item) { } /* Do not modify code below this line */ const items = addItemToArray([1, 2, 3], 4); console.log(items, '<-- should equal [1, 2, 3, 4]');
I tried to return Items but I received an error.
Just push the item into the array and return the array from the function :)
function addItemToArray(array, item) { // .push() will add item to the end of the array array.push(item); return array; } /* Do not modify code below this line */ const items = addItemToArray([1, 2, 3], 4); console.log(items, '<-- should equal [1, 2, 3, 4]');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.