如何在javascript中为单个变量分配多个值

How to assign multiple values in a single variable in javascript?

本文关键字:分配 变量 单个 javascript      更新时间:2023-09-28

我有一个数组,它插入这样的团队ID,

var responsiblePartyId = [];
for (var i in addTeamtask.toteam) {
    responsiblePartyId.push(addTeamtask.toteam[i].SiteUserId);
}

我只需要从上面的数组中获取值,并将其存储到单个变量中。我在下面尝试过,但我分配了数组的最后一个值。

var assignedID;
for (var i = 0; i < responsiblePartyId.length; i++) {
    assignedID= '"' + i, + '"';
}
var assignedID = responsiblePartyId.join(','); // To join all entries with a comma in between
         // If you want them joined using a different character(s), modify accordingly

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join