Javascript examples for String:split
Split string and then loop through each item
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//w ww . jav a 2s. co m var str = '2+3+2'; var numbers = str.split('+'); var sum = 0; for (var i = 0; i < numbers.length; i++) { sum += parseInt(numbers[i]); } console.log(str + ' = ' + sum); } </script> </head> <body> </body> </html>