在这里,我有一个类似下面的数组,然后将数据发送到API,如下所示
{
assignStudents: [
{
isAssigned: true,
binusID: "1640000616",
fullname: "ACHMAD FARID WADJDI",
acadOrg: "DRM",
acadPlan: "Strategy & Growth"
},
{
isAssigned: true,
binusID: "0660003053",
fullname: "AFAN GALIH SALMAN",
acadOrg: "DCS",
acadPlan: "Computer Science"
},
{
isAssigned: false,
binusID: "BN001047135",
fullname: "AGUNG YUNANTO",
acadOrg: "DRM",
acadPlan: "Strategy & Growth
},
],
academicTermID: ""
}
发布数据时出现问题,因此必须首先选择要发布的数据,即binusID和acadOrg。
我的问题是如何过滤包装在数组中的对象内的键?
您可以使用Array.map仅保留所需的对象键,然后再发布数据。下面的工作片段。
var data = {
assignStudents: [
{
isAssigned: true,
binusID: "1640000616",
fullname: "ACHMAD FARID WADJDI",
acadOrg: "DRM",
acadPlan: "Strategy & Growth"
},
{
isAssigned: true,
binusID: "0660003053",
fullname: "AFAN GALIH SALMAN",
acadOrg: "DCS",
acadPlan: "Computer Science"
},
{
isAssigned: false,
binusID: "BN001047135",
fullname: "AGUNG YUNANTO",
acadOrg: "DRM",
acadPlan: "Strategy & Growth"
},
],
academicTermID: ""
};
data.assignStudents = data.assignStudents.map(e => {
return {binusianID: e.binusID, acadOrg: e.acadOrg};
});
console.log(data);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句