How to square each number in array in JavaScript ES6

1 Answer

0 votes
const arr = [1, 2, 3, 4, 5].map(x => x ** 2);

console.log(arr);



/*
run:
   
[ 1, 4, 9, 16, 25 ]

*/

 



answered Mar 22, 2020 by avibootz

Related questions

...