How to append something to an array?

Ask a question+

How do I append an object (such as a string or number) to an array in JavaScript?

add comment

1 Answer


To add anything to an array in JavaScript, you use the array method .push(), it would go something like this:

// Starting array
var exampleArray = ["First","Second","Third","Fourth"];

// Adding "Fifth" to the array

Here is a good reference for adding things to arrays, from W3Schools.

Does this make sense? If not, let me know.

Batman 300
add comment

Your Answer