Here I want to use array method ‘pop’, but i cant bcz num has a returned integer value, so how can i turn the vallue into an arry.
let num = 0;
for(i=0; i<=10; i++){
num = i
let r = num.pop()
console.log(num, r)
}
I expecting —
num return [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] & console [1, 2, 3, 4, 5, 6, 7, 8, 9] 10
2
Answers
You can initialize array by
num = []
.And
num.pop()
will read and delete element.Here is a modified code
.pop() is an array method and it won’t work here because your num variable is not an array.
You can solve it by creating another variable of an empty array, and actually populate that one.
Something like this
let num_array = [];