logo
Search
showing results for - "resize array javascript"
Sterling
17 Jun 2017
1// Quick way
2a = ['A','B','C','D'];
3console.log(a.length); // 4
4a.length = 3;
5console.log(a); // ['A', 'B', 'C'];
6
7// Proper way
8function resize(arr, newSize, defaultValue) {
9    return [ ...arr, ...Array(Math.max(newSize - arr.length, 0)).fill(defaultValue)];
10}
similar questions
changing an array element in javascriptuse length to resize an arrayjs split array into smaller arrayshow to create an array of size n in javascriptreplace array element javascriptjavascript size arrayslice array javascriptjavascript array sizeresize jsmodify array elements javascriptjs array modify elementjavascript resize eventhow to reverse array in javascriptcreate array initialize size javascripthow to modify an arraymodify array jsjavascript middle of arrayjavascript atualize arrayjavascript replace array element6 ways to modify an array javascriptjavascript resize windowcreate array initialize size javascript with value
queries leading to this page
array resize 28 29resize javascript arrayarray resizing in jaascriptresize array jsjavascript resize arrayhow to resize an arraybest way to resize js arrayarray resizearray resizeresize an arrayresize array javascriptresizing arrayresize arrayarray resize javascriptresize array javascript
privacy policyterms of useinstagram
Crafted with  ♥  for everyone

sign in to continue
your answer for
you will get a confirmation link on this - you will have to click that for successful submission of your answer. we require this to keep the website free of spam, bots and unhelpful content
please ensure to add code which is syntactically corrent and executes properly
sign in to continue
ask question on maxinterview
you will get a confirmation link on this - you will have to click that for successful submission of your question. we require this to keep the website free of spam, bots and unhelpful content
please be clear, to the point and respectful
sign in to continue