Imagine you want to append a single item to an array. In this case, the push() method, provided by the array object can help you. So, it would be best if you act as follows:
Please, take into account that push() changes your original array.
For creating a new array, you should implement the concat() method, like this:
Also notice that the concat() method doesn’t add an item to the array, but makes a completely new array that can be assigned to another variable or reassigned to the original one:
If you intend to append multiple items to an array, you can also use the push() method and call it with multiple arguments, like here:
Also, you can use the concat() method passing an items’ list, separated by a comma, as follows:
Either an array:
Notice that this method will not mutate your original array, but will return a new one.
One of the most crucial advantages of an array is that it can contain multiple elements on the contrary with other variables.
An element inside an array can be of a different type, such as string, boolean, object, and even other arrays. So, it means that you can create an array having a string in the first position, a number in the second, and more.