How to use array map() to create new array with the results of run a function for each element in JavaScript

2 Answers

0 votes
var numbers = [4, 9, 16, 25, 36, 49];
var arr = numbers.map(Math.sqrt)

document.write(arr);
 

 
    
/*
run:
          
2,3,4,5,6,7 
        
*/

 



answered Nov 6, 2019 by avibootz
0 votes
var numbers = [4, 9, 16, 25, 36, 49];
var arr = numbers.map((value, index, array) => { return value * 2 });

document.write(arr);
 

 
    
/*
run:
          
8,18,32,50,72,98 
        
*/

 



answered Nov 6, 2019 by avibootz
...