Javascript length property is used to find out the length of characters or it may returns number of elements in an array
Every Character gets counted in this property.
JavaScript Array length Property
The length property returns the number of elements stored in a particular array.
< !DOCTYPE html>
<p>Click the submit button to see result.</p>
<button onclick="myFunction()">submit</button>
<p id="demo"></p>
<script>
function myFunction() {
var n = ["Pranav", "Abhishek", "Ayush", "Rajat","Ravi"];
document.getElementById("demo").innerHTML = n.length;
}
</script>
</body>
</html>
JavaScript String length Property
The length property returns the string length after counting the characters of that string.
<p>Click the button to see result.</p>
<button onclick="myFunction()">click</button>
<p id="demo"></p>
<script>
function myFunction() {
var str = "Pranav Chhabra";
var n = str.length;
document.getElementById("demo").innerHTML = n;
}
</script>
</body>
</html>
0 Comment(s)