gpt4 book ai didi

javascript - 对数组中的对象进行字符串化,但不对数组本身进行字符串化

转载 作者:行者123 更新时间:2023-11-28 18:33:10 25 4
gpt4 key购买 nike

我正在映射我的数组(有很多)。因此,我们的想法是将数组中的所有对象/所有内容字符串化。

  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);

关于javascript - 对数组中的对象进行字符串化,但不对数组本身进行字符串化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599562/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com