Q:

Camelcase string to normal string

How to change NoOfSAP => No Of SAP? I have trying the replace method but it says undefined.
function unCamlelCase(result) {
  return result.key.replace(/([^A-Z]*)([A-Z]*)([A-Z])([^A-Z]*)/g, '$1 $2 $3$4')
    .replace(/ +/g, ' ');
};

How can I change the result key values camel case to normal string?
if (exactMatch) {
  const { ...response } = json[0];
  const result = Object.keys(response).reduce((acc, key) => {let newKey = key.charAt(0).toUpperCase() + key.slice(1);
  return acc;
}, {});

A:

You can go that way:
const camelToWords = (camelCaseWord) => camelCaseWord
  .replace(/([A-Z]+)/g, " $1")
  .replace(/([A-Z][a-z])/g, "$1");

There is also possibility to use existing libraries like lodash:
const _ = require('lodash');
console.log(_.startCase('abcDef'));
// result: Abc Def

