Home > Blockchain >  How to reduce my javascript code 4 lines? have written a conditional statement that is too long plea
How to reduce my javascript code 4 lines? have written a conditional statement that is too long plea

Time:12-30

let getSlotList = \[\];
    if (
      res.data.hasOwnProperty('alley') &&
      res.data.hasOwnProperty('booked') &&
      res.data.hasOwnProperty('reminder')
    ) {
      getSlotList = \[
        ...res.data.alley,
        ...res.data.booked,
        ...res.data.reminder,
      \];
    } else if (
      res.data.hasOwnProperty('alley') &&
      res.data.hasOwnProperty('booked')
    ) {
      getSlotList = \[...res.data.alley, ...res.data.booked\];
    } else if (
      res.data.hasOwnProperty('booked') &&
      res.data.hasOwnProperty('reminder')
    ) {
      getSlotList = \[...res.data.reminder, ...res.data.booked\];
    } else if (
      res.data.hasOwnProperty('alley') &&
      res.data.hasOwnProperty('reminder')
    ) {
      getSlotList = \[...res.data.alley, ...res.data.booked\];
    } else if (res.data.hasOwnProperty('alley')) {
      getSlotList = \[...res.data.alley\];
    } else if (res.data.hasOwnProperty('reminder')) {
      getSlotList = \[...res.data.reminder\];
    } else if (res.data.hasOwnProperty('booked')) {
      getSlotList = \[...res.data.booked\];
    }

    console.log(
      '           
  • Related