Consider an array of objects like this:
data = [{keyOne: 'value1', keyTwo: 'value2'},
{keyOne: 'value3', keyTwo: 'value4'}];
We need to change it to look like this:
data = [{Key one: 'value1', Key two: 'value2'},
{Key one: 'value3', Key two: 'value4'}];
To achieve this transformation, each property value should be converted from camel case to a sentence format, for example keyOne becomes Key one.
A function can be used for this conversion:
function convertToSentence(text) {
const result = text.replace( /([A-Z])/g, " $1" );
const finalResult = result.charAt(0).toUpperCase() + result.slice(1);
return finalResult;
}
The challenge is applying this function to every object in the array. One way is to use data.forEach(item => ... );
Any suggestions on how to approach this task?