我嵌套了如下所示的对象数组:
const data = [
{text: 'node 1'},
{text: 'node 2', chapter_playlist: [{text: 'node 2-1', lesson_playlist: [{text: 'node 3-1'}]}]},
{text: 'node 3'},
{text: 'node 4', chapter_playlist: [{ text: 'node 4-1' }]}
]
Run Code Online (Sandbox Code Playgroud)
如何将每个嵌套属性(如chapter_playlist、lesson_playlist)重命名为“ children ”?
基本上我想更改具有更多子项的属性的名称,如果没有子项则无需更改它。我仍然很困惑如何改变它
预期成绩
const data = [
{text: 'node 1'},
{text: 'node 2', children: [{text: 'node 2-1', children: [{text: 'node 3-1'}]}]},
{text: 'node 3'},
{text: 'node 4', children: [{ text: 'node 4-1' }]}
]
Run Code Online (Sandbox Code Playgroud)