Capitalize first letter of each word in variable

I want to capitalize the first letter of each word of a text stored in a variable
How should it be done? Any help will be much appreciated.

The following command makes everything lower case. I need to add a new command to make the first letters of each word as UpperCase

{
      "Command": "executeScript_Sandbox",
      "Target": "return ${persona_primer_nombre}.toLowerCase()",
      "Value": "persona_primer_nombre",
      "Description": ""
    }

I read about “ProperCase” but couldn’t make it work.
The other option that I thought was extracting the first letter and make it UPPER CASE and merge the 2 variables.

I researched and found this but couldn’t make it work due to my limited knowledge on this area

{
  "Name": "AAA",
  "CreationDate": "2021-6-14",
  "Commands": [
    {
      "Command": "store",
      "Target": "I want to capitalize the first letter of each word of a text stored in a variable How should it be done? Any help will be much appreciated.",
      "Value": "AAA",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "const str = ${AAA};\nconst arr = str.split(\" \"); \nfor(var i=0; i<arr.length; i++)\n  {\n    arr[i]= arr[i].charAt(0).toUpperCase() + arr[i].slice(1);\n\n  }\nconst str2 = arr.join(\" \");\nreturn str2;",
      "Value": "CCCC",
      "Description": ""
    }
  ]
}

Awesome!! You’re making my day!!!