I am currently working on creating a unique custom function that will loop through an array of objects and combine selected object property keys into a single string separated by commas.
Let me explain using some code:
var products = [
{
"id": 1,
"variants": {
"colour": "black"
},
},
{
"id": 2,
"variants": {
"colour": "red"
}
}
];
function joinedByComma(arr, keys) {
// code will go here
}
joinedByComma(products, ["variants", "colour" ]);
// expected output is "black,red"
Can anyone provide suggestions or guidance on how to implement the joinedByComma
function? The length of the array passed in the second parameter can vary based on the depth of the object...