Answers for "js new array of length"

22

how to find length of array js

var array = [1, 2, 3, 4, 5]; // array of size 5

var size = array.length; // add.length to get size

console.log('size : '+size);
//output: size : 5
Posted by: Guest on August-04-2021
24

array length javascript

var numbers = [1, 2, 3, 4, 5];
var length = numbers.length;
for (var i = 0; i < length; i++) {
  numbers[i] *= 2;
}
// numbers is now [2, 4, 6, 8, 10]
Posted by: Guest on December-08-2019
8

javascript size array

let array = [1, 2, 3];
console.log(array.length);
Posted by: Guest on May-25-2020
-4

js length of array

arr = ["a", "b", "c"];
len = arr.length; // 3
Posted by: Guest on January-22-2021
0

set array length js

const array = new Array(myLength)
Posted by: Guest on August-16-2021
0

js new array of length

ES6 gives us Array.from so now you can also use 
Array.from(Array(5)).forEach(alert)

If you want to initialize with a certain value, these are good to knows...
Array.from('abcde'),
Array.from('x'.repeat(5))
or 
Array.from({length: 5}, (v, i) => i)   // gives [0, 1, 2, 3, 4]
Posted by: Guest on March-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language