There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
Out of curiosity: is there a way one can use .length to get the total number of characters in an array?
For example:
const objectives = ['Learn a new languages', 'Read 52 books', 'Run a marathon'];
console.log(objectives.length); // console prints 3
console.log(objectives[0].length) // console prints 21
Is there a way to use .length to print the total number of characters in all three of the items in the array?
I want to know the difference between the index of an array and the .length of an array?
why is that the index always start from zero to count and the .length start from one to count.
Hello, and welcome to the forums, @tera8025290123. The difference is quite straight forward. The length is simply the number of elements, using counting numbers. 0 length means the array is empty.
The index (or indices) correspond with the order of the array, counting from zero on up to the length, minus one. Zero is an index, that of the first element.
array[0]
It is a sequence, and its order never changes even if we shift around the elements. They all take the index of where they are moved to.
A quick question on this, since I just finished this exercise and wanted to try this out… When I log in this, the output is at 50. But I counted the characters and it comes to 48. Where does this take the other ‘2’ from? Could you please provide an answer to that? I tried but couldn’t reach a conclusion on that. Thank you
Blockquote
const objectives = [‘Learn a new languages’, ‘Read 52 books’, ‘Run a marathon’];
Join method joins the given string between those array elements…
Try to understand the below example, It will make you understand that what I am saying …
const objectives = ['Learn a new languages', 'Read 52 books', 'Run a marathon'];
console.log(objectives.length); //=> 3
console.log(objectives[0].length) //=> 21
console.log(objectives.join(''))//=> Learn a new languagesRead 52 booksRun a marathon
console.log(objectives.join("").length)// => 48
console.log(objectives.join(' '))//=> Learn a new languages Read 52 books Run a marathon
console.log(objectives.join(' ').length)// => 50
console.log(objectives.join(','))//=> Learn a new languages,Read 52 books,Run a marathon
console.log(objectives.join(',').length)// => 50
console.log(objectives.join('##'))//=> Learn a new languages##Read 52 books##Run a marathon
console.log(objectives.join('##').length)// => 52