I have a data response of form:
claim_amount_arr: [218691.44]
claim_approval_status: ["In Process"]
percentages_claim: [1]
percentages_claim_amount: [1]
total_claim_arr: [2]
_id: 0
__proto__: Object
I want to convert it to array so as to map it into table further in a component. Since it does not have a key, I am not able to access it's key value pair for mapping. I tried the following approach but then it eliminates all the key from the array:
const summary_props = this.props.summary
//console.log(summary_props); //this console gives me data as shown in image above
const sortedvalue = Object.keys(summary_props).map(key => {
return summary_props[key];
});
console.log(sortedvalue);
Please help.
Try Object.entries() .
In short, it can transform an object into an array.
Edit : More specific here
Object.entries(formData).map(([key, value]) => { //Now you can access both the key and their value })
class ClaimInformation() { constructor(data,index) { this.claim_amount = data.claim_amount_arr[index]; this.claim_approval_status = data.claim_approval_status[index]; this.percentage_claim = data.percentage_claim[index]; this.percentages_claim_amount = data.percentages_claim_amount[index]; this.total_claim = data.total_claim_arr[index]; } }
var claims = []; for(let i = 0; i < response.claim_amount_arr.length; i++){ claims.push(new ClaimInformation(response,i)); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.