我想通过json结构中的关键字获取消息。例如json结构为:
[{ _id: 123, message: 'hello', username: '1' }, { _id: 456, message: 'world', username: '2'}
现在我想获取所有消息并将它们放入一个数组中。如何在javascript中实现这个?谢谢
最佳答案
var json = [{ _id: 123, message: 'hello', username: '1' }, { _id: 456, message: 'world', username: '2'}];
var arr = [];
for(i=0;i<json.length;i++) {
arr.push(json[i].message);
}
console.log(arr);
关于javascript - 如何通过键将对象数组映射到值数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40012997/