I am getting an unexpected result while trying to use nullish coalescing operator on a return value that might be an array or might have an array as a child
const storedKeys = await getStoreKeys();
let keys = storedKeys.keys ?? storedKeys;
console.log(keys);
console.log output:
ƒ keys() { [native code] }
Any idea on what might be going wrong? Thanks.
if
storedObjectis an array, it has a built-inkeys()method (storedObject.keys()is equivalent toObject.keys(storedObject)). So the property isn't null, and it returns this function.Use a ternary that checks if it's an array: