js对象,属性不固定,怎么转数组

我只是一个渣渣
  • 278

"future":{

        "day_20180829":{
            "temperature":"24℃~28℃",
            "weather":"中雨转暴雨",
            "weather_id":{
                "fa":"08",
                "fb":"10"
            },
            "wind":"东南风3-5级",
            "week":"星期三",
            "date":"20180829"
        },
        "day_20180830":{
            "temperature":"24℃~29℃",
            "weather":"大雨-暴雨转雷阵雨",
            "weather_id":{
                "fa":"23",
                "fb":"04"
            },
            "wind":"持续无风向微风",
            "week":"星期四",
            "date":"20180830"
        }}

如上,我想转成[0:xxxxx,1:xxxxx,2:xxxxx]这样的格式。。现在我自己写成了这样。。转换没成功

clipboard.png

回复
阅读 1.8k
1 个回答
const obj= {
    "day_20180829":{
        "temperature":"24℃~28℃",
        "weather":"中雨转暴雨",
        "weather_id":{
            "fa":"08",
            "fb":"10"
        },
        "wind":"东南风3-5级",
        "week":"星期三",
        "date":"20180829"
    },
    "day_20180830":{
        "temperature":"24℃~29℃",
        "weather":"大雨-暴雨转雷阵雨",
        "weather_id":{
            "fa":"23",
            "fb":"04"
        },
        "wind":"持续无风向微风",
        "week":"星期四",
        "date":"20180830"
    }
};
const 你要的 = Object.values(obj);
console.log(你要的);

clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏