I used a class to class to organize everything I needed in this small project and made it require a 2d array to print out a field to the screen
class Field {
constructor(fieldArr) {
this.fieldArr = fieldArr;
}
get field() {
return this.print();
}
print() {
console.log(this.fieldArr.join("n")) // new line made after each array
}
}
const myField = new Field([
["*", "░", "O"],
["░", "░", "░"],
["O", "░", "O"]
])
myField.print()
expected:
*░O
░░░
O░O
got:
*,░,O
░,░,░
O,░,O
3
Answers
You are working with a 2-d array, but you
join()
the outer array.YOu should
map()
each inner item, tojoin()
those (with nothing for now), and thenjoin()
the resulting string with a newlinE:You are working with a multidimensional array… to manipulate data you have to step twice to reach the inner array but the way your code is written it only works on the outer array.
I’ve made an edit to your code to make it work but this is for only manipulating the commas.