---
title: "Discussion on \"How to create a function to take an array and append an element at the end.\" | Hashnode"
description: "Discussion on \"How to create a function to take an array and append an element at the end.\". In this post, we will create a function to take an array and element as an argument and return the array with the element at the end of the array. \nLet's break this down into chunks... \n\nWe need a function. \nAn array and element are required to pass ..."
url: "https://hashnode.com/posts/how-to-create-a-function-to-take-an-array-and-append-an-element-at-the-end/62ff7bbb8bec3d0c4588bd3c"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [How to create a function to take an array and append an element at the end.](https://davidgillick.hashnode.dev/how-to-create-a-function-to-take-an-array-and-append-an-element-at-the-end?utm_source=hashnode&utm_medium=feed)

In this post, we will create a function to take an array and element as an argument and return the array with the element at the end of the array. Let's break this down into chunks... We need a function. An array and element are required to pass ...

Aug 19, 2022 · 3 min read · davidgillick.hashnode.dev  
Updated Aug 22, 2022  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#arrays](https://hashnode.com/tag/arrays)
-   [#javascript-functions](https://hashnode.com/tag/javascript-functions)
-   [#add-element-to-an-array](https://hashnode.com/tag/add-element-to-an-array)
-   [#spread-operator](https://hashnode.com/tag/spread-operator)

## Written by

[Dave Gillick](https://hashnode.com/@Woolley)

@Woolley · London, UK

  
[View profile](https://hashnode.com/@Woolley)

## Responses 1

Markdown supported · ⌘↵ to post

[Panda Codes](https://hashnode.com/@pandacode)

[Aug 22, 2022](https://hashnode.com/posts/how-to-create-a-function-to-take-an-array-and-append-an-element-at-the-end/62ff7bbb8bec3d0c4588bd3c/comment/6302d92d14c73b2c3b913f18)

Is there a reason you'd want to write a function to wrap `array.push()` in this manner? You've actually made a worse option as `array.push` will accept multiple arguments, or you can pass it an entire array with the spread operator.

[Dave Gillick](https://hashnode.com/@Woolley)

[Aug 22, 2022](https://hashnode.com/posts/how-to-create-a-function-to-take-an-array-and-append-an-element-at-the-end/62ff7bbb8bec3d0c4588bd3c/comment/6302d92d14c73b2c3b913f18#reply-630400b109d19537666eae71)

Hi Panda Codes, Many thanks for your feedback. I have updated the post to include why it's best to use the spread operator.
