I have an array of objects which are all instances of the same class like below:
class Foo {
constructor(bar){
this.bar = bar;
}
}
var myArr = [new Foo("1"), new Foo("2"), new Foo("3"), new Foo("4")];
I want to be able to join the bar property of each object in the array into a comma separated string.
Is it possible to call the .join method on the property of an object? If not is below the most efficent way to do this?
var result = "";
for (var i = 0; i < myArr.length; i++){
result += myArr[i].bar+","
}
Or is there another way?