Object destructuring solution for long arrays?

后端 未结 2 1071
天涯浪人
天涯浪人 2020-12-11 18:03

Looking at this code:

let lecture = {
    id: 2,
    title: \"MyTitle\",
    topics: [
    {
        title: \"John\",
        age: 1
    },
    {
        tit         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 18:03

    Probably too late to reply this,

    const index = 65
    const {title: lectureTitle, topics: {[index]: {age: thirdAge}}} = lecture
    

    because in real life we normally would be using dynamic indices for arrays to destructure, square brackets instead of numbers or just { index: {age}} doesn't work.

提交回复
热议问题