I'm feeling stuck.
Check out this code snippet:
const clientInfoPromise = buildPromiseMethod
clientInfoPromise.then((clients) => {
console.log('clients ' + JSON.stringify(clients))
console.log(clients.typeOf)
console.log(_.keys(clients))
This is the current output:
clients {}
undefined
['undefined']
I want to get an empty array when I use _.keys(clients), rather than getting an array with the string 'undefined'.
_.isEmpty(clients) ? [] : _.keys(clients)
doesn't seem to solve the issue, as _.isEmpty
returns false
.
This is where ClientInfoPromise is being defined:
static buildPromiseMethod(cids) {
if (condition) {
// fetch data
const data = [data,data1,data2]
return Promise.resolve(_.zipObject(cids, data));
} else {
const clients = _(cids)
.indexBy()
.mapValues(() => {
return undefined; //contains empty data
})
.value();
return Promise.resolve(clients);
}
}
The values for cids
can be undefined
, []
, or [1,2,3]
(an array of numbers).