Array Given:
const Collection = [{ id: 1 }, { id: 3 }, { id: 2 }, { id: 4 }]
Required String should be:
string = "1,3,2,4"
I have tried to get from forEach() loop to join() each value and save it in a string variable.
expecting result should be a comma separated string.
>Solution :
You can use forEach, but you would have to pair it with something else.
const Collection = [{ id: 1 }, { id: 3 }, { id: 2 }, { id: 4 }];
var res = [];
Collection.forEach(function(item) {
res.push(item.id);
});
res = res.join(",");
console.log(res);