又是甲方奇奇怪怪的接口数据格式要求,传给我的是一个对象,居然要我传过去的时候转换成数组,直接上代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
let obj = {
channel: "0阿奥术大多999",
agam: "其味无穷",
contactNum: "132131",
certId: "x萨达撒",
serviceKey: "dg_10VX7HR",
axgsfd: "fadfa"
}
// 传入一个对象, return一个数组
const objToArr = obj => {
let arr = []
Object.keys(obj).forEach(item => {
let newObj = {}
newObj[item] = obj[item]
arr.push(newObj)
})
return arr
}
console.log(objToArr(obj))
</script>
</body>
</html>
效果图: