Length question


#1

I wonder know whether word “lengh” is mean the number of letters or not ?


#2

If you use .length on a string, it will return the number of characters in that string; that includes letters, spaces, numbers, and punctuation.

If you use .length on an array, it will return the number of elements in that array.

  • [].length – 0 items
  • ['hello'].length – 1 item (a string)
  • [1, 'bye', ['abc',3]].length – 3 items (a number, a string, and an array)

If you have an array inside an array, and you want to count all the sub-items, you can use the spread operator (...).

[1, 'bye', ...['abc',3]].length turns into [1, 'bye', 'abc', 3].length – 4 items (a number, 2 strings, another number)

–Frankie