Reputation: 643
Say I have an array of words:
let words = ['hello', 'world']
And I want to capitalize each one of them, what I'm doing is:
let words = ['hello', 'world']
for (let word of words) {
word = word.toUpperCase();
}
But each word is not binded to the iterable element, and the end result is the unchanged array.
Is there any way to bind each of the words to the array elements?
(Besides of the classic for(i=0; i
Upvotes: 2
Views: 38
Reputation: 1333
You can use map
for this:
let words = ['hello', 'world'];
words = words.map(word => {
return word.toUpperCase();
});
console.log(words);
Upvotes: 5