Answer the question
In order to leave comments, you need to log in
Why, after assignment, an array of objects becomes a string array in which objects are represented as strings?
there is such a function on the server:
function findBooks(res, data = {}, fullBookInfo = null) {
Book.find(data, (err, books) => {
if (err) {
res.json(config.getRespData(true, MSG.internalErr500, err));
} else if (fullBookInfo === "true") {
const book = _.clone(books[0]);
Authors.find(
{ _id: { $in: book.bookInfo.authors } },
(authorsErr, authors) => {
if (authorsErr) {
book.bookInfo.authors = null;
} else {
book.bookInfo.authors = [...authors];
}
}
);
res.json(config.getRespData(false, null, book));
} else {
res.json(config.getRespData(false, null, books));
}
});
}
book.bookInfo.authors = [...authors];
["{ createdAt: 2019-10-07T11:43:18.207Z,\n _id:
5d666abbe480bd41207b1398,\n authorName: 'Джордж Мартин',\n __v: 0 }"]
Answer the question
In order to leave comments, you need to log in
Are you querying MongoDB? This is all because the database gives you JSON.
If the query used Promise, then to get an array of records, you would need to add .toArray() to find().
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question