javascript把json对象转为数组
本文介绍了javascript把json对象转为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
转换前是这样的:
var articles = [{
title: 'hello',
content: 'hello world',
created_at:'2017-08-30 13:45:15'
},{
title: 'foo',
content: 'foo bar',
created_at:'2017-08-30 13:45:15'
}];
我想把它转成这样:
var articles2 = [
[ 'hello', 'hello world', '2017-08-30 13:45:15' ],
[ 'foo', 'foo bar','2017-08-30 13:46:06' ]
];
用js应该怎么做呢?
解决方案
var articles = [{
title: 'hello',
content: 'hello world',
created_at:'2017-08-30 13:45:15'
},{
title: 'foo',
content: 'foo bar',
created_at:'2017-08-30 13:45:15'
}]
var result = articles.map(item => {
return Object.values(item)
})
这篇关于javascript把json对象转为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文