0

I have displayed the name of the arrays in the UI and I'm trying to convert those as a normal sentence: Example: thisIsArrayOne, thisIsArrayTwo => should be This Is Array One, This Is Array Two.

I'm using toTitleCase method but seems that is not working

<div>{name.toTitleCase()}</div>
alar
  • 207
  • 1
  • 4
  • 15
  • How about Javascript solutions of this: https://stackoverflow.com/q/5582228/4636715 . Btw, I could not get what exactly you mean by *array name* or *name of the arrays* – vahdet Feb 06 '20 at 08:51
  • @vahdet yes, it's working. thank you! – alar Feb 06 '20 at 08:57

2 Answers2

0

You can try

  let array=["thisIsArrayOneTwo","thisIsArrayTwo"];
   let newArray=array.map(r=>r.split(/(?=[A-Z])/).join(" "));
   console.log(newArray); 

Code here: https://stackblitz.com/edit/react-v8ltfo

0

You can try like this -- This is React functional component .

  

import React from 'react';
    
 const New = (props) =>{
    let val = ['thisIsArrayOne', 'thisIsArrayTwo'];
     const cheangeUpperCase = ()=>{
      
         let a =val.map((val, index)=>(  
            val= val.charAt(0).toUpperCase() + val.slice(1)
         ));
         console.log(a.join(','))
         return a.join(',');
     }
     
    return(
        <div>
        {cheangeUpperCase()}
        </div>
    );
}
export default New;