I'm getting an a response from a server which is javascript object which has array in itself, and I would like to do some operation in client - I would like to simplify that by converting response to some simple kind of string which I would like to display to user, here's the code:
Server response looks like this:
0: {productId: 25, productType: 2, productCodes: Array(3)}
1: {productId: 26, productType: 1, productCodes: Array(3)}
length: 2
productCodes: Array(3)
0: {productId: 0, productType: 0, code: "PRODUCT01", desc: "Description1"}
1: {productId: 0, productType: 0, code: "PRODUCT01", desc: "Description2"}
2: {productId: 0, productType: 0, code: "PRODUCT01", desc: "Description3"}
How can I convert this to create new array to get something like this:
{productType:2, productCodes: "Description1 (PRODUCT01), Description2 (PRODUCT02), Description3 (PRODUCT03)" }
{productType:1...}
So basically to create a string which as Description and Code in braces ( ) with comma separated values?
I have tried something like this but this didn't lead me anywhere:
// const data = response.data.productCodes.map((currElement, index) => ({
// productType = currElement.transactionType,
// productCodes = currElement.productCodes.map((elem, index)=>({
// }))
// }));
Any kind of help would be awesome!
Thanks !
.map()on each product to convert it toDescription1 (PRODUCT01), and then.join(', ')on the result of that to join them all