-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.array.js
More file actions
29 lines (25 loc) · 757 Bytes
/
map.array.js
File metadata and controls
29 lines (25 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
function map(document) {
// console.log(document);
const property ="ids";
let the_array = document[property];
let objectArray = [];
for (let elem of the_array) {
let objToReturn = {};
objToReturn._id = document._id;
objectArray.push(MapObject(elem , objToReturn));
}
return objectArray;
}
function MapObject(input, objToReturn) {
for (const key in input) {
if (input.hasOwnProperty(key)) {
const element = input[key];
if (typeof element !== "object")
objToReturn[key] = element;
else if (!Array.isArray(element))
objToReturn = MapObject(element, objToReturn)
}
}
return objToReturn;
}
exports.map = map;