Get multiple character positions in array via map function - Javascript Array

Javascript examples for Array:map

Description

Get multiple character positions in array via map function

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//w  w  w  .j  a v a2s  . c o  m
var mystr = 'w.wer,ads,';
var pos = mystr.split(/[,.]/).slice(0,-1).map(function(val, i, a) { a[i] = val.length+(a[i-1]?a[i-1]+1:0); return a[i]; });
console.log(pos);
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials