{}和[]之间的主要区别是什么?
我想知道何时使用它以及如何存储数据
education: [
{
school: {
type: String,
required: true
},
fieldofstudy: {
type: String,
required: true
},
from: {
type: Date,
required: true
},
to: {
type: Date
},
current: {
type: Boolean,
default: false
},
description: {
type: String
}
}
]
social: {
youtube: {
type: String
},
twitter: {
type: String
},
facebook: {
type: String
},
linkedin: {
type: String
},
instagram: {
type: String
}
}
我希望看到一些示例,以了解在哪里使用以及何时不使用它。
答案 0 :(得分:0)
{ }
可以包含索引数据(带有字符串索引),而[ ]
只能包含未索引的数据(默认情况下为数字索引)。
如您的示例所示,
此处,默认情况下数据在0索引上:
education: [{ school: { type: String, required: true }, fieldofstudy: { type: String, required: true }, from: { type: Date, required: true }, to: { type: Date }, current: { type: Boolean, default: false }, description: { type: String } }]
这里的数据已为字符串索引
social: { youtube: { type: String }, twitter: { type: String }, facebook: { type: String }, linkedin: { type: String }, instagram: { type: String } }