filterVal = ['id', 'title', 'author']
jsonData = [
{
id: 1,
title: 2,
author: 3,
pageviews: 4,
display_time: 5
},
{
id: 1,
title: 2,
author: 3,
pageviews: 4,
display_time: 5
}
]
要求返回:
[
{
id: 1,
title: 2,
author: 3
},
{
id: 1,
title: 2,
author: 3,
}
]
实现方法:
function formatJson(filterVal, jsonData) {
return jsonData.map(v => {
return filterVal.map(j => {
return v[j]
})
})
}