簡體   English   中英

Vue.JS 將對象數組轉換為數組數組

[英]Vue.JS convert array of objects into array of arrays

在 vue 中,我的數據如下所示:

data: {
    messages: []
  }

但是從api返回的數據看起來像這樣(對象數組)

messages: Array(1)
 0: Object
  message: "qwerqwer"

如何將對象數組轉換為數組數組?

這將完全符合您的要求,但您應該嘗試理解而不是盲目復制它:

messages = messages.map(
    function(message){
        return message.message;
    }
);

閱讀Array.prototype.map()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM