title: How do extract string to some pattern using javascript
body: <p>I am having some phone number as string , i have split into in order to add some extension inside.What would be better solution rather than inserting at each index. Here is what i had tried.<code>1234567891346</code> is input output would be like <code>(123) - 456 - 7891 Ext - 346</code> .</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>let phoneStr= '12345678912346';
       phoneStr.split("")
       let phoneNo =[];
       phoneNo[0]='(' ;
       phoneNo[1]=phoneStr[0] ;
       phoneNo[2]=phoneStr[1] ;
       phoneNo[3]=phoneStr[2] ;
       phoneNo[4]=')' ;
       phoneNo[5]=' - ' ;
  
       phoneNo[6]=phoneStr[3] ;
       phoneNo[7]=phoneStr[4] ;
       phoneNo[8]=phoneStr[5] ;
       phoneNo[9]=' - ' ;
  
       phoneNo[10]=phoneStr[6] ;
       phoneNo[11]=phoneStr[7] ;
       phoneNo[12]=phoneStr[8] ;
       phoneNo[13]=phoneStr[9] ;
       phoneNo[14]=' Ext - ' ;
  
       phoneNo[15]=phoneStr[10] ;
       phoneNo[15]=phoneStr[11] ;
       phoneNo[16]=phoneStr[12] ;
       phoneNo[17]=phoneStr[13] ;
       phoneNo[18]=phoneStr[14] ;
       console.log( phoneNo.toString().replace(/,/g , ""));</code></pre>
  </div>
  </div>
  </p>