I'm creating an object, putting the attributes of that object into an array and then mapping the array to HTML output and I end up with line after line of commas? Where are these commas coming from?
let results = []
class Polygon {
constructor() {
this.name = "Hexagon"
this.edges = 6
this.size = 1
}
setName(value) {
this.name = value
}
setEdges(value) {
this.edges = value
}
setSize(value) {
this.size = value
}
getArea() {
return this.size * this.size
}
}
let shape = new Polygon()
shape.setName("Square")
shape.setEdges(4)
shape.setSize(6)
results.push(shape.name)
results.push(shape.edges)
results.push(shape.size)
results.push(shape.getArea())
console.log(results)
resultsDiv = document.querySelector('#results')
resultsDiv.innerHTML = results.map(r => '<p>' + r + '</p>')
Here's the fiddle with the HTML: https://jsfiddle.net/ruzel/qyrczkup/3/