javascript create array of objects with map
var result = arr.map(person => ({ value: person.id, text: person.name }));
console.log(result)var arr = [{
id: 1,
name: 'bill'
}, {
id: 2,
name: 'ted'
}]
var result = arr.map(person => ({ value: person.id, text: person.name }));
console.log(result)export class RegularPoPart {
Id : number;
TimecardId : number;
TimecardRef : number;
PurchaseOrder : string;
PartNumber : string;
LineItem : string;
QuantityRequested : number;
QuantityInspected : number;
QuantityAccepted : number;
QuantityRejected : number;
RejectionReason : string;
ChargeNumber : string;
AccountNumber : string;
IsOnHold : boolean;
}
newPo: RegularPoPart[] = [];
const po = [{
Id : 1,
PoNumber : '123456',
PartNumber : '999999',
LineItem : '0010',
QuantityRequested : 20,
InspectionTypeId : 0,
InspectionTypeName : '',
Description : 'Test Desc',
ChargeNumber : '',
QuantityInspected : 20,
QuantityAccepted : 20,
QuantityRejected : 0,
RejectReason : ''
},
{
Id : 2,
PoNumber : '654321',
PartNumber : '888888',
LineItem : '0020',
QuantityRequested : 50,
InspectionTypeId : 0,
InspectionTypeName : '',
Description : 'Test Desc',
ChargeNumber : '',
QuantityInspected : 50,
QuantityAccepted : 0,
QuantityRejected : 50,
RejectReason : 'Test Reject Reason'
}];
this.newPo = this.po.map(item => {
return {
Id: item.Id,
TimecardId: null,
TimecardRef: null,
PurchaseOrder: item.PoNumber,
PartNumber: item.PartNumber,
LineItem: item.LineItem,
QuantityRequested: item.QuantityRequested,
QuantityInspected: item.QuantityInspected,
QuantityAccepted: item.QuantityAccepted,
QuantityRejected: item.QuantityRejected,
RejectionReason: item.RejectReason,
ChargeNumber: item.ChargeNumber,
AccountNumber: item.Description,
IsOnHold: null
};
});