I want to generate JSON data in an array to pass to another component. For this, I followed a method as follows. But I guess I wasn't very good. I'm new to this business and trying to learn.
employeeMoney: any[] = [];
employeeId: any[] = [];
this.employeeMoney.push(event.target.value);
this.employeeId.push(employId);
This is how I throw the data I get from the user with the input. I'm pushing data into this array I created in the same function.
this.employeeMoney.map(function(item) {
blopp.all.money.push(item);
});
this.employeeId.map(function(item) {
blopp.all.id.push(item);
});
let blopp: any = {
all: [{id: '', money:''}]
};
My goal here is to collect data from 2 different array lists into a single list. Then I want to generate the JSON data in the format I want using the data I have collected in this single list. But here I am encountering an error. when you enter the data in the input. This error pops up in the console.
ERROR ReferenceError: Cannot access 'blopp' before initialization
i couldn't solve this error. I'm trying to create such a JSON structure using the latest money and id data.
blopp.map(function(item: any) {
blopp.money.push({
"employee_id" : '',
"amount" : item,
"currency" : 'USD'
})
});
But I have a question here, how can I print 2 different data in the same array list to the same JSON structure.