var a = [5, [2, 8, [35, 48, [24]], 15, [12, 85]], [[1, [34, [26]], [15]]]]; alert(JSON.stringify(a)) a = a.join(' ').split(/\D+/) ; alert(JSON.stringify(a))