const sentence = 'i have learned something new today';
const words = sentence.split(" ");
for (var j = 0; j < words.length; j++) {
words[j] = words[j].charAt(0).toUpperCase() + words[j].slice(1);
}
const newSentence = words.join(" ");
console.log(newSentence);
Although the code provided a simple loop to capitalize the first letter of each word, I found myself struggling to grasp the concept of accessing elements of the array using arr[i]. I feel like I need a more in-depth explanation to fully understand it.
My understanding is that when the code references “array[i]”, it is actually referring to the loop variable “i”. Therefore, the for loop is comparing the value of “i” with the variable called “largest”. Once “i” exceeds largest, the value of largest is updated to the new number.
Despite finding some explanation through research, I still have unanswered questions and seek a more comprehensive understanding.