Map an array of arrays

后端 未结 6 1773
太阳男子
太阳男子 2021-02-07 02:17

Is there a method in lodash to map over an array of arrays

I would like to do something like this so that it keeps the structure of the array.

def double         


        
6条回答
  •  长情又很酷
    2021-02-07 02:51

    const deepMap=(input,callback)=>input.map(entry=>entry.map?deepMap(entry,callback):callback(entry))
    
    //test 
    
    deepMap([1,2,3,[1,2]],x=>x*2) // [1,4,9,[1,4]]
    

提交回复
热议问题