I have a function with an array of numbers, I want to square it but I want them in the array box like [4,9,16] Each time i try to do that, it throws back a NAN output in the console. The numbers come back listed as in a straight line.
digit = (num) => {
let digits = String(num).split('')
.map(Number);
for(let i = 0; i < digits.length;
i++){
let square = Math.pow(digits,2);
console.log(square);
}
};
digit(234);
output : NaN
digit = (num) => {
let digits = String(num).split('')
.map(Number);
for(let i = 0; i < digits.length;
i++){
let square = Math.pow(digits[i],2);
console.log(square);
}
};
digit(234);
output : 4
9
16
Is it possible to have my output as [4,9,16]?