How to append something to an array?

Ask a question+
0

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

add comment

1 Answer

1

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
exampleArray.push("Fifth");

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