Hi Friends 👋,
Welcome To Infinitbility! ❤️
To find the length of a string in an array in javascript, use array[0].length
it will return length of your first string of array.
Today, I’m going to show you How do I find the length of a string in an array in javascript, as mentioned above, I’m going to create a sample array of string variable then I will use the array index method to get the first string and check their length.
Let’s start today’s tutorial on how do you find the length of a string in an array in javascript.
Javascript gets the first letter of the string
Here, we will do
- Create a sample array string variable with data.
- Use array index and length to get length of array string
- Get length of string from the array of object
// Create a sample array string variable with data.
let arr1 = ["infintbility", "aguidehub", "sortoutcode"];
// Use array index and length to get length of array string
console.log("First Array string: ", arr1[0].length)
console.log("Second Array string: ", arr1[1].length)
console.log("Third Array string: ", arr1[2].length)
// Get length of string from the array of object
let arr2 = [
{ name:"infintbility"},
{ name:"aguidehub" },
{ name: "sortoutcode" }
];
console.log("First Array object string: ", arr2[0].name.length)
console.log("Second Array object string: ", arr2[1].name.length)
console.log("Third Array object string: ", arr2[2].name.length)
Output
I hope it helps you, All the best 👍.