What is the concept of Array.map?

前端 未结 8 1806
甜味超标
甜味超标 2020-11-30 06:36

I am having problems understanding the concept of Array.map. I did go to Mozilla and Tutorials Point, but they provided very limited info regarding this.

<
8条回答
  •  孤城傲影
    2020-11-30 07:26

    Probably most people coming here (like me) just want a basic array.map usage example:

    myArray = [1,2,3]
    mappedArray = [];
    
    mappedArray = myArray.map(function(currentValue){
         return currentValue *= 2;
    })
    
    //myArray is still [1,2,3]
    //mappedArray is now [2,4,6]
    

    This is it at it's most basic. For additional parameers, check out: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map

提交回复
热议问题