Metode peta. PENTING
function toUpper(string) {
return string.toUpperCase();
}
const cats = ['Leopard', 'Serval', 'Jaguar', 'Tiger', 'Caracal', 'Lion'];
const upperCats = cats.map(toUpper);
console.log(upperCats);
// [ "LEOPARD", "SERVAL", "JAGUAR", "TIGER", "CARACAL", "LION" ]
Here we pass a function into cats.map(), and map() calls the function
once for each item in the array, passing in the item. It then adds the
return value from each function call to a new array, and finally returns
the new array. In this case the function we provide converts the item to
uppercase, so the resulting array contains all our cats in uppercase:
Ojikutu Hakeem