var arr = [1,2,3, [4, 5], 6, [7, [8, 9], 10]];
var jsonResult = {};
function arr2Obj(arr) {
var result = {};
for (i in arr) {
if (Object.prototype.toString.call(arr[i]) == '[object Array]') {
result[i] = arr2Obj(arr[i]);
} else {
// Not array type
result[i] = arr[i];
}
}
return result;
}
jsonResult = JSON.stringify(arr2Obj(arr));
console.log(jsonResult);