Is there a shorthand for JavaScript's (or even in coffeescript) .push()
, when appending a value to an array? Much like php's $array[] = 'added to array';
.
JavaScript Array push() The push() method adds new items to the end of an array. The push() method changes the length of the array.
Alternatives of push() method in JavaScript Approach 1: Use the length property to insert the element at the end of the array. Example: This example implements the above approach.
The opposite of push() (as the question is titled) is pop() .
The arr. push() method is used to push one or more values into the array. This method changes the length of the array by the number of elements added to the array. Parameters This method contains as many numbers of parameters as the number of elements to be inserted into the array.
You'll just have to use .push()
.
The use of coffeescript will only afford you the convenience of dropping the parentheses.
You can use arr[arr.length] = "new value"
but there's no other shortcut.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With