簡體   English   中英

數組化對象而不是數組本身

[英]stringify objects within an array but not the array itself

我正在映射我的數組(有很多)。 因此,想法是將數組中的所有對象/所有內容都字符串化。

  const studentInfoObj = students.map(value => (
      // for each student return json string of the objects
      // how can I just stringify everything within the array?
      // but not the array itself. Just all the objects inside?
      return JSON.stringify(???);
  ));

這是當前的json

{"Michael00043":
     // stringify from this point
     [
          {"student_num":"20293290000HJ93",
           "campus":"McHale",
           "major":"PSI"
          },
     ],
      ... more objects
     [
          {"medical_doc":"st.laurance hos",
           "emergency_contact":"Adam Harley",
           "blood_type":"O"
          },
          {"hospital":"st.laurance hos",
           "ward":"B",
          },
     ]
...

你是這個意思嗎?

 var students = { "Michael00043": [{ "student_num": "20293290000HJ93", "campus": "McHale", "major": "PSI" }, { "medical_doc": "st.laurance hos", "emergency_contact": "Adam Harley", "blood_type": "O" }] }; // loop through each student for (student in students) { // stringy each value in the array that each student is students[student] = students[student].map(value => JSON.stringify(value)); } console.log(students); 

暫無
暫無

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

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