I have this simple code:
var num = [12,13]
class Test {
constructor(num){
this.num = num
}
change() {
this.num[1] = 5
}
}
test = new Test(5)
test.change()
alert(test.num[0] + ' x ' + num)
I am trying to change the value of this.num through the change method. However, I get the following error:
Uncaught TypeError: Cannot create property '1' on number '5'
Can someone please explain what I am doing wrong here? Here's a fiddle, if it helps. Thank you
5to the constructor ofTest, a number is not iterabletest = new Test(num)