javascript - 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();
}
解决方案
null 是假的,所以
if (data.storageId) {
ref.child('images').child(`${data.storageId}.jpg`).delete();
}
这也将满足 storageId 未定义的情况。