I have an array with strings and I want to return these items as a single string but with a space between them.
listProperties() {
this.properties = "";
this.state.withoutSuit.forEach(function (i, j) {
this.properties += i;
this.properties += " ";
});
console.log(this.properties);
return this.properties;
}
So in the constructor I have this.state.withoutSuit as my array, and this.properties as the place I'll store the spaced out string version of it.
In the function first I set this.properties to an empty string, and then I want to fill it up with the withoutSuit array items.
But when i go into the forEach loop, this.properties is undefined. I presume this is because the "this" is now referring not to the constructor but to this.state.withoutSuit :- is that right?
And if so, how do I reference the properties variable from within the loop?
Thank you!