Javascript Ionic-无法使用可变键推送对象
我正在尝试创建一个电话号码数组,用于ionic native SMS软件包。这是相当简单的代码:Javascript Ionic-无法使用可变键推送对象,javascript,arrays,angular,typescript,ionic-framework,Javascript,Arrays,Angular,Typescript,Ionic Framework,我正在尝试创建一个电话号码数组,用于ionic native SMS软件包。这是相当简单的代码: let array; let promises_array = []; this.storage.get('username').then((val) => { console.log('in storage'); this.follow = this.af.list('/profiles/stylists/' + val + "/followers"); th
let array;
let promises_array = [];
this.storage.get('username').then((val) => {
console.log('in storage');
this.follow = this.af.list('/profiles/stylists/' + val + "/followers");
this.subscription = this.follow.subscribe(items => items.forEach(item => {
promises_array.push(new Promise((resolve, reject) => {
console.log(JSON.stringify(item) + " item item item");
let arr = Object.keys(item);
console.log(item[arr[0]] + " type followers");
array.push(item[arr[0]]); ;
resolve();
}))
}));
Promise.all(promises_array).then(() => {
let month1 = date.getUTCMonth;
let date1 = date.getUTCDate;
this.sms.send(array, val + " just opened up a spot at " + time + " on " + month1 + " " + date1 + "!")
.catch(e => { console.log(JSON.stringify(e))});
})
boool = false;
})
我得到的错误是应用程序中出现的运行时错误-
Uncaught (in promise): TypeError undefined is not an object (evaluating 'array_1.push')
我已确认数组_1.push对应于以下行:
array.pushitem[arr[0]]
意思是项目[arr[0]]未定义,但控制台输出为:
[10:54:49] console.log: in storage
[10:54:49] console.log: {"V":"7818646634"} item item item
[10:54:49] console.log: 7818646634 type followers
[10:54:52] console.log: "Message cancelled."
第三行显示它识别出[arr[0]]是什么,当它推送它时,它只是认为它未定义。任何帮助都会很好,谢谢。您没有将数组变量定义为数组,因此它不知道可以将其推送到
let数组
你应该做:
让数组=[] 我们都去过: