Created
April 15, 2015 13:51
-
-
Save demonixis/6a92a01520746efdc934 to your computer and use it in GitHub Desktop.
Resize an array with JavaScript is easy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var array = [1, 2, 3, 4, 5]; | |
console.log(array.length); // 5 | |
array.length--; | |
console.log(array.length); // 4 | |
array.length += 15; | |
console.log(array.length); // 19 |
this changes only the length and does not add null values.
thanks bro.
So which elements are kept?
So which elements are kept?
Here's a running example @dzonekl, the elements at the end of the array are removed.
https://runkit.com/makstaks/resizing-an-array-in-javascript
Thanks bro
this is super helpful
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Short and useful example. So basically length serves dual purpose.