Conditional spread element

后端 未结 5 2138
無奈伤痛
無奈伤痛 2021-02-19 03:50
const cond = false

const extraInfo = [
  {
    a: 11,
    b: 25
  },
  {
    a: 12,
    b: 34
  },
  {
    a: 1,
    c: 99
  }
]

const userInfo = [
  {
    z: 8
  },
          


        
5条回答
  •  感情败类
    2021-02-19 04:21

    let getMyValue = cond ? [].concat(extraInfo, userInfo) : userInfo;
    

    let check this

    const extraInfo = [
      {
        a: 11,
        b: 25
      },
      {
        a: 12,
        b: 34
      },
      {
        a: 1,
        c: 99
      }
    ];
    const userInfo = [
      {
        z: 8
      },
      {
        z: 10
      },
    ];
    
    const cond = false;
    let getMyValue = cond ? [].concat(extraInfo, userInfo) : userInfo;
    
    console.log(getMyValue)

提交回复
热议问题