Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create an array of square of given numbers in javascript?

I want to create an array of numbers which gives the square of those numbers; for example I tried this but it does not work:

let arr = [1, 2, 30, 50, 7, 83, 670]
let n = array.map((num)=>{
return num % num
})

console.log(n)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I can see there is a small problem in your code.

just replace ( % ) sign with ( * ) between num % num.

The code should be like this

let arr = [ 1, 2, 30, 50, 7, 83, 670 ] 
let n = array.map((num){
return num * num
}) 
console.log(n).

The expected output should be the square of the numbers in the given array.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading