[英]Vue.JS convert array of objects into array of arrays
In vue my data looks like this:在 vue 中,我的数据如下所示:
data: {
messages: []
}
But the data returned from the api looks like this (array of objects)但是从api返回的数据看起来像这样(对象数组)
messages: Array(1)
0: Object
message: "qwerqwer"
How do I convert a array of objects into an array of arrays?如何将对象数组转换为数组数组?
This will do exactly what you want it to do, but you should try to understand and not just blind copy it:这将完全符合您的要求,但您应该尝试理解而不是盲目复制它:
messages = messages.map(
function(message){
return message.message;
}
);
Read about Array.prototype.map()阅读Array.prototype.map()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.