首页 > 解决方案 > Firebase Storage check if value is null in JavaScript

问题描述

I want delete image only when storageId is not null.

I checked for null like so and value is null but it's fired so exception says not found that image.

How can I check if it's null?

  const data = snapshot.data();
  const ref = firebase.storage().ref();
  if (data.storageId != null) {
    ref.child('images').child(`${data.storageId}.jpg`).delete();
  }

标签: javascriptfirebasegoogle-cloud-firestorefirebase-storage

解决方案


null 是假的,所以

if (data.storageId) {
  ref.child('images').child(`${data.storageId}.jpg`).delete();
}

这也将满足 storageId 未定义的情况。


推荐阅读