How to use .length in Javascript
By FoxLearn 12/18/2024 7:02:05 AM 13
In JavaScript, `.length` is a property that returns the number of items in an array or the number of characters in a string.
For example:
// For an array let fruits = ['apple', 'banana', 'cherry']; console.log(fruits.length); // Output: 3 // For a string let message = 'Hello, world!'; console.log(message.length); // Output: 13
In this examples, .length
helps determine how many elements are in an array or how many characters are in a string.
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
12/19/2024