React JS Certification Training Course
- 7k Enrolled Learners
- Live Class
The value returned is an unsigned integer. The length property can be specified as:
We can refer to the program below for a better understanding, start with installation first:
Another way to use the length property is as follows:
It should be noticed that in case of strings, the length property returns the number of characters present in the string, while in case of arrays, the number of elements present in the array is returned.
In the following program, the last element of the array is accessed by using the following method: (music.length-1), after which the element is displayed.
Length can be used to find out the number of words present in a string. We also make use of the split function to create an array.
Total Number Of Words: 9
Finding out the length of an array is not only a fundamental requirement, but also holistic approach to many problems.
Got a question for us? Mention them in the comments section of this blog and we will get back to you.