У меня есть массив:
"data": [
{
"photo": "no-photo.jpg",
"_id": "5e9aabd9c975a10a7ee48476",
"title": "Title",
"description": "Description",
"phone": "77477926783",
"fromLocation": "5e9aa8a9c975a10a7ee48474",
"toLocation": "5e9aa8bac975a10a7ee48475",
"price": 1000000,
"date": "1998-02-23T00:00:00.000Z",
"user": "5e91729f147813258ef1f373",
"createdAt": "2020-04-18T07:27:21.743Z",
"__v": 0,
"courses": [],
"id": "5e9aabd9c975a10a7ee48476"
}
]
, и я использую for...loop
:
for (const item of res.advancedResults.data) {
console.log(item)
}
это дает нормально:
{
"photo": "no-photo.jpg",
"_id": "5e9aabd9c975a10a7ee48476",
"title": "Title",
"description": "Description",
"phone": "77477926783",
"fromLocation": "5e9aa8a9c975a10a7ee48474",
"toLocation": "5e9aa8bac975a10a7ee48475",
"price": 1000000,
"date": "1998-02-23T00:00:00.000Z",
"user": "5e91729f147813258ef1f373",
"createdAt": "2020-04-18T07:27:21.743Z",
"__v": 0,
"courses": [],
"id": "5e9aabd9c975a10a7ee48476"
}
Но когда я копирую это как:
for (const item of res.advancedResults.data) {
console.log({...item})
}
Это дает:
{ '$__':
InternalCache {
strictMode: true,
selected: {},
shardval: undefined,
saveError: undefined,
validationError: undefined,
adhocPaths: undefined,
removing: undefined,
inserting: undefined,
saving: undefined,
version: undefined,
getters: {},
_id: 5e9aabd9c975a10a7ee48476,
populate: undefined,
populated: undefined,
wasPopulated: false,
scope: undefined,
activePaths: [StateMachine],
pathsToScopes: {},
cachedRequired: {},
session: null,
'$setCalled': Set {},
ownerDocument: undefined,
fullPath: undefined,
emitter: [EventEmitter],
'$options': [Object] },
isNew: false,
errors: undefined,
_doc:
{ photo: 'no-photo.jpg',
_id: 5e9aabd9c975a10a7ee48476,
title: 'Title',
description: 'Description',
phone: '77477926783',
fromLocation: 5e9aa8a9c975a10a7ee48474,
toLocation: 5e9aa8bac975a10a7ee48475,
price: 1000000,
date: 1998-02-23T00:00:00.000Z,
user: 5e91729f147813258ef1f373,
createdAt: 2020-04-18T07:27:21.743Z,
__v: 0 },
'$locals': {},
'$$populatedVirtuals': { courses: [] },
'$init': true }
Как правильно скопировать объект?