1var array = [1, 2, 3, 4, 5]; // array of size 5
2
3var size = array.length; // add.length to get size
4
5console.log('size : '+size);
6//output: size : 5
1var numbers = [1, 2, 3, 4, 5];
2var length = numbers.length;
3for (var i = 0; i < length; i++) {
4 numbers[i] *= 2;
5}
6// numbers is now [2, 4, 6, 8, 10]
7
1 var x = [];
2 console.log(x.size());
3 console.log(x.length);
4 console.log(x.size()==x.length);
5 x =[1,2,3];
6 console.log(x.size());
7 console.log(x.length);
8 console.log(x.size()==x.length);
9//arjun
1ES6 gives us Array.from so now you can also use
2Array.from(Array(5)).forEach(alert)
3
4If you want to initialize with a certain value, these are good to knows...
5Array.from('abcde'),
6Array.from('x'.repeat(5))
7or
8Array.from({length: 5}, (v, i) => i) // gives [0, 1, 2, 3, 4]