猿问

如何将json对象转成数组???

如何将json对象转成数组???
json对象:
{"phone_num_wxx":"用户手机号","phone_city_wxx":"手机号归属地","sex_wxx":"性别","income_wxx":"收入","age_wxx":"年龄"}

希望转换成这样的数组形式:
["phone_num_wxx","用户手机号","phone_city_wxx","手机号归属地","sex_wxx","性别","income_wxx","收入","age_wxx","年龄"]


森栏
浏览 1497回答 1
1回答

侃侃尔雅

这个是你要的[key,value,name,value, ...]const list = []Object.keys(json).forEach(function(item, index) {     this.push( item, json[item])}, list)但我想你要是循环渲染应该要这样好用些(需要就直接循环渲染就可以,对应的值就是key 和 value)[{},{},{}]const list = Object.keys(json).map((item, index) => ({key: item, value:json[item]}))
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答