Simply, I want to store results in this array and want this result outside this.data
function I want to pass these results as this.data
and when I'm importing this function i use this.data
database = admin.database();
class PrivateSingleton {
constructor() {
let a = [];
const keyref = database.ref("data");
const finalfinaldata = keyref.get().then((data) => {
const finalData = data.val();
// console.log(finalData)
return finalData;
});
this.data = finalfinaldata.then(function (result) {
// console.log(result);
a.push(result);
});
console.log(a);
this.iv = "IVVV";
this.key = "aaa";
}
}
class Singleton {
constructor() {
throw new Error("Use Singleton.getInstance()");
}
static getInstance() {
if (!Singleton.instance) {
Singleton.instance = new PrivateSingleton();
}
return Singleton.instance;
}
}
module.exports = Singleton;
OUTPUT
: [] // Here I want my result in this array.