■98381 / ) |
Re[1]: 多重配列のkey値指定の値を取りたい |
□投稿者/ 魔界の仮面弁士 (3209回)-(2021/11/10(Wed) 10:29:36)
|
■No98379 (センチ さん) に返信
> それとも階層を一つ一つ下階層がある場合、再起的に回さないとだめでしょうか?
提示されたコードだと、'[object Object]' という文字列が取り出されそうに見えました。
意図を理解できているのか自信がありませんが…とりあえず再帰的に書いてみます。
function buildError(errors) {
const results = [];
errors.forEach((el) => {
if ( el.constraints !== void 0) {
Object.entries(el.constraints).forEach(([key, value]) => results.push(value));
} else {
Array.prototype.push.apply(results, buildError(el.children))
}
});
return results;
}
|
|