How to put a null check on this code


Joined
Jan 4, 2022
Messages
1
Reaction score
0
Code:
toFormData(): FormData {
  const service = new FormDataService(
    this,
    (key: string, value: any, formData: FormData) => {
      if (key === 'files' && this.files !== undefined) {
        let i = 0
        for (const f of this.files) {
          if (f.fileObject !== undefined) {
            formData.append(`files[${i}][file]`, f.fileObject)
          }
          if (f.id !== undefined) {
            formData.append(`files[${i}][id]`, f.id)
          }
          i = i + 1
        }
      }
        formData.append(key, value)
    }
  )
  service.setDateType(['carry_transfer_date', 'started_at', 'ended_at'])
  service.setExclude(['toFormData', 'created_at', 'updated_at'])
  return service.execute()
}

I wanna put the null check on this code because formData convert everything on string so i am having a null string like this "null" when the input is empty so i wanna put the null check on the formData.append(key, value). if anyone can help me i would love it thank you
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top