What’s up programmer, okay? Let’s learn something new?
There are many situations in which we need to check the number of elements in an array
You can even define how a system will proceed, according to this answer.
Through the length property, we can identify how many elements there are in the array, check it out:
let nomes = ['Matheus', 'João', 'Pedro']; console.log(nomes.length); // 3
Notice that a number is returned to us, with the number of elements
And then our problem is solved
Curiosity: number of characters in the string
Another interesting point of the length property is that it works for strings as well.
And in this case, we will receive the number of letters that the word or phrase contains, like this:
let frase = "Como verificar quantidade de elementos no array"; console.log(frase.length); // 47
Notice that the return is a number as well
We learned that we can determine the number of elements in an array with the length property
That will returns us a number, with the number of elements
The property works for strings too, and in this data type it checks the number of characters