var str = '1-2;2-450;3-16;4-73;5-21;', arr, i = 0, len, numbers; arr = str.split(';'); len = arr.length; console.log(arr); for(; i < len; i +=1) { numbers = arr[i].split('-'); if(numbers) { alert(numbers.join(',')); } }