質問: before + custom + after; ```
回答: たとえばこう ``` var json='{"test1":"aaa","test2":{"first_name":"tarou","last_name":"hanako"},"test3":{"email":"test@test.com","prefecture":"東京都"},"test4":"bbb"}'; var a=JSON.parse(json); var b=[]; for(var i in a){ if(typeof a[i]=="string"){ b.push([i,a[i]]); }else{ for(var j in a[i]){ if(typeof a[i][j]=="string"){ b.push([j,a[i][j]]); } } } } console.log(b); ``` 入れ子の入れ子 ======== arguments.calleeは無名関数を再帰処理するときの自分自身です strictで使えないなら、名前を付けてやるのが手っ取り早いかもしれません ``` var json='{"test1":"aaa","test2":{"first_name":"tarou","last_name":"hanako","test_test":{"test5":"xxx"}},"test3":{"email":"test@test.com","prefecture":"東京都"},"test4":"bbb"}'; var a=JSON.parse(json); var b=[]; (function(x){ for(var i in x){ if(typeof x[i]=="string"){ b.push([i,x[i]]); }else{ arguments.callee(x[i]); } } })(a); console.log(b); ``` strict ======= ``` "use strict"; const json='{"test1":"aaa","test2":{"first_name":"tarou","last_name":"hanako","test_test":{"test5":"xxx"}},"test3":{"email":"test@test.com","prefecture":"東京都"},"test4":"bbb"}'; const a=JSON.parse(json); const b=[]; const func=(x)=>{ for(var i in x){ if(typeof x[i]=="string"){ b.push([i,x[i]]); }else{ func(x[i]); } } }; func(a); console.log(b); ```