Search⌘ K
AI Features

Solution: Going Loopy Over Arrays

Explore how to apply JavaScript array methods like map and filter to manipulate strings within arrays. Learn to convert array elements to uppercase using map and filter out elements based on character conditions, gaining hands-on skills for practical programming.

We'll cover the following...

Solution 1

Here is a possible solution for the capitals function that uses the map to return a new array of the same words written in uppercase.

Javascript (babel-node)
const arr = ["red", "car", "arrow", "burger", "javascript"];
function capitals(arr) {
return arr.map(word => word.toUpperCase());
}
console.log(capitals(arr));

Explanation

  • Line 1: Declares a constant variable arr and assign it an array containing five strings.

  • Line 3–5: Defines a function called capitals that takes an array as an argument. Inside the function:

    • ...