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
1var myString = "string test";
2var stringLength = myString.length;
3
4console.log(stringLength); // Will return 11 because myString
5// is 11 characters long...
1var colors = ["Red", "Orange", "Blue", "Green"];
2var colorsLength=colors.length;//4 is colors array length
3
4var str = "bug";
5var strLength=str.length;//3 is the number of characters in bug
1const clothing = ['shoes', 'shirts', 'socks', 'sweaters'];
2
3console.log(clothing.length);
4// expected output: 4
1// The "function length" in JS evaluates to the number of it's params
2
3const sum = (a, b) => a + b;
4const log = (s) => console.log(s);
5const noop = () => {};
6
7console.log(sum.length); // 2
8console.log(log.length); // 1
9console.log(noop.length); // 0
1var x = 'Mozilla';
2var empty = '';
3
4console.log('Mozilla is ' + x.length + ' code units long');
5/* "Mozilla è lungo 7 unità di codice" */
6
7console.log('La stringa vuota ha una lunghezza di
8 ' + empty.length);
9/* "La stringa vuota ha una lunghezza di 0" */