Object.keys forEach returns undefined

前端 未结 2 1861
轻奢々
轻奢々 2020-12-21 01:10

I have the following function which takes in an object as an argument and uses it to manipulate the object

function manipulateData(obj){
    var data = Objec         


        
相关标签:
2条回答
  • 2020-12-21 01:44

    Maybe use .map() as this returns a new Array?

    function manipulateData(obj){
        var data = Object.keys(obj).map(function(index){
             //Perform the manipulation 
             return obj;
        }
    
        return data;
    }
    
    0 讨论(0)
  • 2020-12-21 01:49

    forEach doesn't return anything. If you want to make a new Array by transforming the existing one, use map.

    0 讨论(0)
提交回复
热议问题