js length code example

Example 1: length of dict js

// check length of dictionary

let dict = {a:1 , b:2 , c:3}

console.log(Object.keys(dict).length) // expected result : 3

Example 2: MDN array length

const clothing = ['shoes', 'shirts', 'socks', 'sweaters'];

console.log(clothing.length);
// expected output: 4

Example 3: js string length

let str = "foo";
console.log(str.length);
// 3

Example 4: 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]

Example 5: javascript string lentrh

var myString = "string test";
var stringLength = myString.length;

console.log(stringLength); // Will return 11 because myString 
// 							  is 11 characters long...

Example 6: javascript longitud de un string

cadena_primitiva = String("barra"); // crea una Cadena primitiva
cadena_primitiva = "barra"; // crea una Cadena primitiva
cadena_primitiva.length; // 5