2024年07月20日 建站教程
下面web建站小编给大家介绍2中对象转换成数组的方法,并且去掉参数名!
方法一:Object.values(obj)
var week = { "星期六": "2022/10/08", "星期日": "2022/10/09", "星期一": "2022/10/10", "星期二": "2022/10/11", "星期三": "2022/10/12", "星期四": "2022/10/13", "星期五": "2022/10/14" } console.log('输出结果', Object.values(week)) //['2022/10/08', '2022/10/09', '2022/10/10', '2022/10/11', '2022/10/12', '2022/10/13', '2022/10/14']
方法二:for-in循环
var week = { "星期六": "2022/10/08", "星期日": "2022/10/09", "星期一": "2022/10/10", "星期二": "2022/10/11", "星期三": "2022/10/12", "星期四": "2022/10/13", "星期五": "2022/10/14" } var arr = []; for(let i in week) { arr.push (week[i]) } console.log(arr); //['2022/10/08', '2022/10/09', '2022/10/10', '2022/10/11', '2022/10/12', '2022/10/13', '2022/10/14']
本文链接:http://so.lmcjl.com/news/8832/