我只是想尝试一下,看看第二个可选参数如何作为数组工作。我希望它最终能解决{"name":"Nikita", "surname": "Ivanov", "age": 19, "friends":[{},{},{}]}
。但与此同时,错误输出仍在继续,似乎未定义 surname 属性,为什么?
let obj = {
name: 'Nikita',
surname: 'Ivanov',
age: 19,
friends: [
{ name: 'Kira', surname: 'Platt', age: 25 },
{ name: 'Victor', surname: 'Smith', age: 30 },
{ name: 'Victoria', surname: 'Blunt', age: 23 }
]
};
console.log(JSON.stringify(obj, [name, surname, age, friends]));