Javascript examples for Array Operation:Array Element
Find character in array and replace it with new values
<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 a2 s . c o m*/ var rows = ['2','5','50','55-60', '74','80-84','123']; var out = rows.reduce(function (p, c) { if (c.indexOf('-') > -1) { var range = c.split('-'); for (var i = range[0], l = range[1]; i <= l; i++) { p.push(+i); } } else { p.push(+c); } return p; }, []); console.log(out) } </script> </head> <body> </body> </html>