Arrays

Append Without Mutation

Append Without Mutation

Some array methods change the existing array, while other patterns create a separate array with the update applied. That distinction matters when previous state must stay trustworthy, such as UI state, undo history, or cached data.

For this helper, the returned array should include the new item at the end. The input array should still contain exactly what it contained before the function was called.

Your task: Complete withAppended so it returns a new array with item added at the end. Do not change the array passed into the function.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Append Without Mutation

Some array methods change the existing array, while other patterns create a separate array with the update applied. That distinction matters when previous state must stay trustworthy, such as UI state, undo history, or cached data.

For this helper, the returned array should include the new item at the end. The input array should still contain exactly what it contained before the function was called.

Your task: Complete withAppended so it returns a new array with item added at the end. Do not change the array passed into the function.

Free with a JS Exercises account

Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.

By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.

Console

Run code to see output.