I'm trying to concatenate values from "seller" Key in a new variables "sellerList" but I'm not achieving to find a good solution.
const data = {
page: {},
product: {
attributes: {
condition: 'used',
offer: {
offer1: {
condition: 'used',
offerID: '1111',
seller: 'Ben',
sellerID: 'abc',
},
offer2: {
condition: 'used',
offerID: '2222',
seller: 'manu',
sellerID: 'def',
},
offer3: {
condition: 'used',
offerID: '3333',
seller: 'Ben',
sellerID: 'abc',
},
},
},
},
};
I found this post which has a similar issue, but it's not working on my side
As we can't use map method on object, I pushed my object into an array like this:
dataArr = [];
dataArr.push(data);
Then I used the following code to concatenate:
const sellersList = Object.keys(digitalData)
.map((o) => o.seller)
.join(';');
console.log('Offer list :' + sellersList);
But this returns an empty string: "Offer list :;"
So my goal is to have a final string like this : "ben;manu;ben"
Does anyone have an idea how to arrange the code fit with my case ? Thank you for your help and your time.
Object.values(data.product.attributes.offer).map(e=>e.seller).join(";")