Just getting into functional programming with .forEach(), .map(), .reduce(), .filter()
var arr = [
{name: 'John', cars: '2', railcard: 'yes', preferences: ['taxi', 'tram', 'walking']},
{name: 'Mary', cars: '0', railcard: 'no', preferences: ['cyling', 'walking', 'taxi']},
{name: 'Elon', cars: '100000', railcard: 'no', preferences: ['Falcon 9', 'self-driving', 'Hyper-loop']}
];
I'm attempting to capitalise the names using .forEach() , but I'm having difficulty applying any methods to the result.
var capitaliseName = function (x) {
return x.toUpperCase();
};
var arrCapitals = arr.forEach(function(name) {
return capitaliseName( arr.name );
});
The above result is returning empty. I could really use a bit of an explanation.
The output I'm expecting is:
var arr = [
{name: 'JOHN', cars: '2', railcard: 'yes', preferences: ['taxi', 'tram', 'walking']},
{name: 'MARY', cars: '0', railcard: 'no', preferences: ['cyling', 'walking', 'taxi']},
{name: 'ELON', cars: '100000', railcard: 'no', preferences: ['Falcon 9', 'self-driving', 'Hyper-loop']}
];
I previously asked this question How do I replace a string with integers in a multi-dimensional array