Typescript - forEach迭代对象和数组

时间:2018-04-22 18:58:37

标签: angular mongodb typescript

在常数" x"可以是一个或多个"用户对象"。 "用户对象"有一些属性,其中一个是" profession"。用户可以拥有一个或多个职业"。所以"用户"保留一个或多个职业ID。我希望每个用户对象的专业ID都能到达professionIdsToDelete - 所以我迭代每个用户"对象并在其中迭代"职业"。

当我使用控制台登录" professionIdsToDelete"我得到了例如"单身ID"和"一对ids":

(2)[数组(1),数组(2)] 0:[" NehR5yNTdHYR82oGi"] 1:(2)[" RQyJfQxaixWETK8ky"," 8t35cao62W6Nz5LqY&# 34;]长度:2__proto__:数组(0)

我需要这个:[" NehR5yNTdHYR82oGi"," RQyJfQxaixWETK8ky"," 8t35cao62W6Nz5LqY"]

我做错了什么? Thnx的建议。

从控制台编写userInArray示例:

removeUser() {

    let professionIdsToDelete = [];

    this.usersToDeleteSub = MeteorObservable.subscribe('usersByUserIds', this.selectedUsers).subscribe(() => {

      const x = Users.find({ 
        _id: { 
            $in: this.selectedUsers 
        }
      }).fetch();
      console.log(x);

      x.forEach((userInArray) => {
        let professionsInUser = [];
        professionsInUser.push(userInArray.profession);

        professionsInUser.forEach((professionId) => {
          professionIdsToDelete.push(professionId);
        })

        console.log(professionIdsToDelete);

      })



    ► {_id: "DXZNwqCy8ptz5HCYH", createdAt: Wed Jan 17 2018 16:19:30 GMT+0100 (CET), services: {…}, emails: Array(1), profile: {…}, …}
     createdAt: Wed Jan 17 2018 16:19:30 GMT+0100 (CET) {constructor: ƒ}
        email: "xxx"
    ► emails: [{…}]
    ► profession: Array(2)
        0:"RQyJfQxaixWETK8ky"
        1:"8t35cao62W6Nz5LqY"
        length: 2
      __proto__: Array(0)
    ► profile:{name: "Zdenek", surename: "Flaksa", phone: "53455", buildingId: "nwXxEg2FAjBqZX9zH"}
    ► services:{password: {…}, resume: {…}}
       _id:"DXZNwqCy8ptz5HCYH"
    ► __proto__:Object

0 个答案:

没有答案