Convert object's properties and values to array of key value pairs

前端 未结 6 2076
长情又很酷
长情又很酷 2020-12-03 01:40

I\'m fairly new to JavaScript and am not sure this is possible to do but basically I would like to take an object and convert it into an array of strings in the format;

6条回答
  •  萌比男神i
    2020-12-03 01:54

    var obj =[
                {'2018-05-07':1},
                {'2018-05-08':3},
                {'2018-05-09':2}
            ];
    
            for(var i of obj) {
                var key = Object.keys(i).toString();
                console.log(i,'=',i[key]);
            }
    

    Result

    :

提交回复
热议问题