how to merge an array and an object that are related? - javascript

I need to merge an array and one object that has a same product id, consider these two as an example:
myArr = [
{
"id": 60,
"productID": 7,
"reservationDate": "2021-07-29T00:11:30.88",
"reservationFinishDateAndHour": "2021-07-28T13:00:30.88",
"reservationStartDateAndHour": "2021-07-28T09:00:30.88",
"userID": 70,
},
{
"id": 61,
"productID": 10,
"reservationDate": "2021-07-29T00:11:30.88",
"reservationFinishDateAndHour": "2021-07-28T13:00:30.88",
"reservationStartDateAndHour": "2021-07-28T09:00:30.88",
"userID": 70,
}
]
myObj = {
"companyID": 1008,
"createdBy": "Unknown",
"createdDate": "2021-07-27T00:00:00",
"finishWorkingHour": "2021-07-27T18:00:00",
"groupOfImage": null,
"id": 7,
"lastModifiedBy": "Ghods",
"lastModifiedDate": "2021-07-27T00:00:00",
"productCategories": null,
"productDetail": "Casual",
"productName": "Casual",
"productPrice": 0,
"startWorkingHour": "2021-07-27T08:00:00",
}
and I need by comparing productID from myArr to id in myObj get this array:
myResult = [
{
"id": 60,
"productID": 7,
"reservationDate": "2021-07-29T00:11:30.88",
"reservationFinishDateAndHour": "2021-07-28T13:00:30.88",
"reservationStartDateAndHour": "2021-07-28T09:00:30.88",
"userID": 70,
},
{
"companyID": 1008,
"createdBy": "Unknown",
"createdDate": "2021-07-27T00:00:00",
"finishWorkingHour": "2021-07-27T18:00:00",
"groupOfImage": null,
"id": 7,
"lastModifiedBy": "Ghods",
"lastModifiedDate": "2021-07-27T00:00:00",
"productCategories": null,
"productDetail": "Casual",
"productName": "Casual",
"productPrice": 0,
"startWorkingHour": "2021-07-27T08:00:00",
}
]

Use Array#filter to get rid of the items with a different productID and push myObj to the resulting array:
var myArr = [
{
"id": 60,
"productID": 7,
"reservationDate": "2021-07-29T00:11:30.88",
"reservationFinishDateAndHour": "2021-07-28T13:00:30.88",
"reservationStartDateAndHour": "2021-07-28T09:00:30.88",
"userID": 70,
},
{
"id": 61,
"productID": 10,
"reservationDate": "2021-07-29T00:11:30.88",
"reservationFinishDateAndHour": "2021-07-28T13:00:30.88",
"reservationStartDateAndHour": "2021-07-28T09:00:30.88",
"userID": 70,
}
]
var myObj = {
"companyID": 1008,
"createdBy": "Unknown",
"createdDate": "2021-07-27T00:00:00",
"finishWorkingHour": "2021-07-27T18:00:00",
"groupOfImage": null,
"id": 7,
"lastModifiedBy": "Ghods",
"lastModifiedDate": "2021-07-27T00:00:00",
"productCategories": null,
"productDetail": "Casual",
"productName": "Casual",
"productPrice": 0,
"startWorkingHour": "2021-07-27T08:00:00",
}
const result = myArr.filter((e, i) => e.productID == myObj.id);
result.push(myObj)
console.log(result);

Related

Filter an Array containing several arrays with objects inside

I am trying to filter a multidimensional array with the inner array containing an object. Every post I have found on here looks like the example below, and all the solutions were pretty much the same and were not successful for me.
let arr = [ { name: 'brent', age: 123 } ];
This is closest I can get, I can console log the filter and see it filtering, but I cannot find out why my array is returning undefined.
let filteredData = [];
let responseData.results = [...]; //The contents of this array are below in the next block
filteredData = responseData.results.forEach((group) =>
{
group.filter(({ customerName }) => customerName.includes(searchTerm));
});
console.log(filteredData); //returns as undefined?
let responseData.results = [
[
{
"id": "e62d6610-04aa-4e92-806f-0449ab3becad",
"customerName": "Immunics",
"enduserName": "Everest",
"productId": 4,
"productName": "fugiat",
"createdBy": "Keith",
"created": "2013-10-31",
"expires": "2011-03-03"
},
{
"id": "3be2967d-cd92-488b-97e3-a8001da6d1c5",
"customerName": "Techtrix",
"enduserName": "Lunchpad",
"productId": 2,
"productName": "sit",
"createdBy": "Odessa",
"created": "2010-02-25",
"expires": "2011-05-22"
},
{
"id": "a67861ae-4e1b-4637-af45-096d6ed7a50f",
"customerName": "Kaggle",
"enduserName": "Strezzo",
"productId": 4,
"productName": "consequat",
"createdBy": "Matilda",
"created": "2010-09-05",
"expires": "2011-08-01"
},
{
"id": "182f84d5-fc27-414c-b011-0e26a9b8e688",
"customerName": "Idealis",
"enduserName": "Blurrybus",
"productId": 0,
"productName": "veniam",
"createdBy": "Merle",
"created": "2012-02-02",
"expires": "2014-05-22"
},
{
"id": "cc05e705-3b5f-4fe6-8c6e-1873fd3834ac",
"customerName": "Furnigeer",
"enduserName": "Harmoney",
"productId": 5,
"productName": "anim",
"createdBy": "Humphrey",
"created": "2010-08-15",
"expires": "2012-06-06"
}
],
[
{
"id": "f2d0ff8e-31ad-4415-8089-cce9df68d119",
"customerName": "Neocent",
"enduserName": "Inear",
"productId": 3,
"productName": "duis",
"createdBy": "Christian",
"created": "2010-01-23",
"expires": "2013-05-18"
},
{
"id": "485095fa-ac86-475c-9a7c-ad449334060d",
"customerName": "Digiprint",
"enduserName": "Bristo",
"productId": 0,
"productName": "occaecat",
"createdBy": "Moran",
"created": "2010-09-30",
"expires": "2014-06-14"
},
{
"id": "d3cacece-1f96-4055-8672-4e506b73e437",
"customerName": "Nexgene",
"enduserName": "Viasia",
"productId": 7,
"productName": "exercitation",
"createdBy": "John",
"created": "2012-07-23",
"expires": "2014-03-31"
},
{
"id": "7fe019e3-7175-48a0-9e2d-1681ce1bfb64",
"customerName": "Quilm",
"enduserName": "Hawkster",
"productId": 3,
"productName": "do",
"createdBy": "Stevens",
"created": "2014-04-28",
"expires": "2013-07-27"
},
{
"id": "7c83a2ea-aa43-4413-af86-02fcd20740e3",
"customerName": "Zillacon",
"enduserName": "Zanity",
"productId": 5,
"productName": "dolor",
"createdBy": "Cathryn",
"created": "2010-07-05",
"expires": "2011-11-26"
}
],
[
{
"id": "2fc29e02-ae0c-413f-ba5a-270a8ba73e5a",
"customerName": "Zepitope",
"enduserName": "Cujo",
"productId": 4,
"productName": "quis",
"createdBy": "Aurora",
"created": "2013-03-22",
"expires": "2014-09-27"
},
{
"id": "07020c5e-7512-456b-af77-3f95d3b8724b",
"customerName": "Melbacor",
"enduserName": "Elemantra",
"productId": 0,
"productName": "amet",
"createdBy": "Pitts",
"created": "2010-09-06",
"expires": "2014-08-14"
},
{
"id": "be9ecd9d-7060-43a2-83b8-b05c52954b9c",
"customerName": "Combot",
"enduserName": "Circum",
"productId": 7,
"productName": "ex",
"createdBy": "Mindy",
"created": "2013-07-05",
"expires": "2014-07-26"
},
{
"id": "991a986b-bd3b-426a-9fc8-113a312c4a19",
"customerName": "Canopoly",
"enduserName": "Accusage",
"productId": 3,
"productName": "proident",
"createdBy": "Cohen",
"created": "2014-02-09",
"expires": "2011-03-17"
},
{
"id": "d843e391-c56d-4dc4-a1d1-dc1b936bc9bd",
"customerName": "Mobildata",
"enduserName": "Eargo",
"productId": 4,
"productName": "culpa",
"createdBy": "Kathie",
"created": "2013-04-03",
"expires": "2012-07-03"
}
],
[
{
"id": "940c6df9-0bbb-43d0-a463-23ba6754a0bb",
"customerName": "Signity",
"enduserName": "Bovis",
"productId": 8,
"productName": "occaecat",
"createdBy": "Monroe",
"created": "2013-09-03",
"expires": "2014-03-23"
},
{
"id": "7479851f-8bba-448b-9af4-75076d81c61f",
"customerName": "Zilladyne",
"enduserName": "Mazuda",
"productId": 8,
"productName": "voluptate",
"createdBy": "Bertie",
"created": "2012-05-03",
"expires": "2010-09-11"
},
{
"id": "dda601dc-6671-43ca-847f-53a90e61f123",
"customerName": "Farmex",
"enduserName": "Greeker",
"productId": 7,
"productName": "eiusmod",
"createdBy": "Jody",
"created": "2010-06-17",
"expires": "2010-09-19"
},
{
"id": "dee1e763-bc49-4b14-87c9-41c7dee01763",
"customerName": "Fibrodyne",
"enduserName": "Besto",
"productId": 7,
"productName": "ex",
"createdBy": "Arlene",
"created": "2012-01-29",
"expires": "2013-10-14"
},
{
"id": "89d69c32-c801-469f-b40f-3d8c85184b08",
"customerName": "Sustenza",
"enduserName": "Omatom",
"productId": 9,
"productName": "consectetur",
"createdBy": "Pruitt",
"created": "2011-03-24",
"expires": "2014-09-13"
}
],
[
{
"id": "2a1d82fc-d7df-4fde-bd4c-97fabccf217e",
"customerName": "Essensia",
"enduserName": "Comverges",
"productId": 8,
"productName": "aliquip",
"createdBy": "White",
"created": "2010-06-23",
"expires": "2014-04-02"
},
{
"id": "f16e04f8-8431-43ac-8315-9822435fe9b0",
"customerName": "Accruex",
"enduserName": "Gluid",
"productId": 6,
"productName": "veniam",
"createdBy": "Kim",
"created": "2010-07-14",
"expires": "2010-04-09"
},
{
"id": "47728404-a86a-4f91-a4fb-d54c6da88a74",
"customerName": "Miracula",
"enduserName": "Gonkle",
"productId": 2,
"productName": "proident",
"createdBy": "Moon",
"created": "2013-07-08",
"expires": "2010-09-10"
},
{
"id": "96810031-64e0-4565-ae0f-308db3fbf7eb",
"customerName": "Viocular",
"enduserName": "Toyletry",
"productId": 3,
"productName": "sit",
"createdBy": "Callahan",
"created": "2014-10-28",
"expires": "2011-01-11"
},
{
"id": "fd223cf3-7f1b-4afb-bccf-cf1907a33334",
"customerName": "Genekom",
"enduserName": "Chorizon",
"productId": 3,
"productName": "ipsum",
"createdBy": "Calhoun",
"created": "2013-09-12",
"expires": "2011-02-27"
}
]
]
You have two common ways of going about this.
Either you can do a map:
const filteredData = responseData.results.map((group) => {
return group.filter(({ customerName }) => customerName.includes(searchTerm));
});
Or even shorter with the implicit inline return:
const filteredData = responseData.results.map((group) =>
group.filter(({ customerName }) => customerName.includes(searchTerm))
);
Or a reduce to get rid of the non-filtered objects that provide a hit from responseData.
const filteredData = responseData.results.reduce((result, group) => {
const match = group.filter(({ customerName }) =>
customerName.includes(searchTerm)
);
if (match) result.push(match);
return result;
}, []);
More information:
MDN - reduce()
MDN - map()
It's a variable naming mistake. You haven't changed filteredData. Rename filteredLicenses to filteredData and it should work.
You may use reduce method to filter each group (sub array) and push those filtered groups to the resulting array if the filtered group has at least one item. Using map method will push empty groups to the resulting array and that's why reduce should be used to prevent that.
Here's a live demo:
const results = [
[{
"id": "e62d6610-04aa-4e92-806f-0449ab3becad",
"customerName": "Immunics",
"enduserName": "Everest",
"productId": 4,
"productName": "fugiat",
"createdBy": "Keith",
"created": "2013-10-31",
"expires": "2011-03-03"
},
{
"id": "3be2967d-cd92-488b-97e3-a8001da6d1c5",
"customerName": "Techtrix",
"enduserName": "Lunchpad",
"productId": 2,
"productName": "sit",
"createdBy": "Odessa",
"created": "2010-02-25",
"expires": "2011-05-22"
},
{
"id": "a67861ae-4e1b-4637-af45-096d6ed7a50f",
"customerName": "Kaggle",
"enduserName": "Strezzo",
"productId": 4,
"productName": "consequat",
"createdBy": "Matilda",
"created": "2010-09-05",
"expires": "2011-08-01"
},
{
"id": "182f84d5-fc27-414c-b011-0e26a9b8e688",
"customerName": "Idealis",
"enduserName": "Blurrybus",
"productId": 0,
"productName": "veniam",
"createdBy": "Merle",
"created": "2012-02-02",
"expires": "2014-05-22"
},
{
"id": "cc05e705-3b5f-4fe6-8c6e-1873fd3834ac",
"customerName": "Furnigeer",
"enduserName": "Harmoney",
"productId": 5,
"productName": "anim",
"createdBy": "Humphrey",
"created": "2010-08-15",
"expires": "2012-06-06"
}
],
[{
"id": "f2d0ff8e-31ad-4415-8089-cce9df68d119",
"customerName": "Neocent",
"enduserName": "Inear",
"productId": 3,
"productName": "duis",
"createdBy": "Christian",
"created": "2010-01-23",
"expires": "2013-05-18"
},
{
"id": "485095fa-ac86-475c-9a7c-ad449334060d",
"customerName": "Digiprint",
"enduserName": "Bristo",
"productId": 0,
"productName": "occaecat",
"createdBy": "Moran",
"created": "2010-09-30",
"expires": "2014-06-14"
},
{
"id": "d3cacece-1f96-4055-8672-4e506b73e437",
"customerName": "Nexgene",
"enduserName": "Viasia",
"productId": 7,
"productName": "exercitation",
"createdBy": "John",
"created": "2012-07-23",
"expires": "2014-03-31"
},
{
"id": "7fe019e3-7175-48a0-9e2d-1681ce1bfb64",
"customerName": "Quilm",
"enduserName": "Hawkster",
"productId": 3,
"productName": "do",
"createdBy": "Stevens",
"created": "2014-04-28",
"expires": "2013-07-27"
},
{
"id": "7c83a2ea-aa43-4413-af86-02fcd20740e3",
"customerName": "Zillacon",
"enduserName": "Zanity",
"productId": 5,
"productName": "dolor",
"createdBy": "Cathryn",
"created": "2010-07-05",
"expires": "2011-11-26"
}
],
[{
"id": "2fc29e02-ae0c-413f-ba5a-270a8ba73e5a",
"customerName": "Zepitope",
"enduserName": "Cujo",
"productId": 4,
"productName": "quis",
"createdBy": "Aurora",
"created": "2013-03-22",
"expires": "2014-09-27"
},
{
"id": "07020c5e-7512-456b-af77-3f95d3b8724b",
"customerName": "Melbacor",
"enduserName": "Elemantra",
"productId": 0,
"productName": "amet",
"createdBy": "Pitts",
"created": "2010-09-06",
"expires": "2014-08-14"
},
{
"id": "be9ecd9d-7060-43a2-83b8-b05c52954b9c",
"customerName": "Combot",
"enduserName": "Circum",
"productId": 7,
"productName": "ex",
"createdBy": "Mindy",
"created": "2013-07-05",
"expires": "2014-07-26"
},
{
"id": "991a986b-bd3b-426a-9fc8-113a312c4a19",
"customerName": "Canopoly",
"enduserName": "Accusage",
"productId": 3,
"productName": "proident",
"createdBy": "Cohen",
"created": "2014-02-09",
"expires": "2011-03-17"
},
{
"id": "d843e391-c56d-4dc4-a1d1-dc1b936bc9bd",
"customerName": "Mobildata",
"enduserName": "Eargo",
"productId": 4,
"productName": "culpa",
"createdBy": "Kathie",
"created": "2013-04-03",
"expires": "2012-07-03"
}
],
[{
"id": "940c6df9-0bbb-43d0-a463-23ba6754a0bb",
"customerName": "Signity",
"enduserName": "Bovis",
"productId": 8,
"productName": "occaecat",
"createdBy": "Monroe",
"created": "2013-09-03",
"expires": "2014-03-23"
},
{
"id": "7479851f-8bba-448b-9af4-75076d81c61f",
"customerName": "Zilladyne",
"enduserName": "Mazuda",
"productId": 8,
"productName": "voluptate",
"createdBy": "Bertie",
"created": "2012-05-03",
"expires": "2010-09-11"
},
{
"id": "dda601dc-6671-43ca-847f-53a90e61f123",
"customerName": "Farmex",
"enduserName": "Greeker",
"productId": 7,
"productName": "eiusmod",
"createdBy": "Jody",
"created": "2010-06-17",
"expires": "2010-09-19"
},
{
"id": "dee1e763-bc49-4b14-87c9-41c7dee01763",
"customerName": "Fibrodyne",
"enduserName": "Besto",
"productId": 7,
"productName": "ex",
"createdBy": "Arlene",
"created": "2012-01-29",
"expires": "2013-10-14"
},
{
"id": "89d69c32-c801-469f-b40f-3d8c85184b08",
"customerName": "Sustenza",
"enduserName": "Omatom",
"productId": 9,
"productName": "consectetur",
"createdBy": "Pruitt",
"created": "2011-03-24",
"expires": "2014-09-13"
}
],
[{
"id": "2a1d82fc-d7df-4fde-bd4c-97fabccf217e",
"customerName": "Essensia",
"enduserName": "Comverges",
"productId": 8,
"productName": "aliquip",
"createdBy": "White",
"created": "2010-06-23",
"expires": "2014-04-02"
},
{
"id": "f16e04f8-8431-43ac-8315-9822435fe9b0",
"customerName": "Accruex",
"enduserName": "Gluid",
"productId": 6,
"productName": "veniam",
"createdBy": "Kim",
"created": "2010-07-14",
"expires": "2010-04-09"
},
{
"id": "47728404-a86a-4f91-a4fb-d54c6da88a74",
"customerName": "Miracula",
"enduserName": "Gonkle",
"productId": 2,
"productName": "proident",
"createdBy": "Moon",
"created": "2013-07-08",
"expires": "2010-09-10"
},
{
"id": "96810031-64e0-4565-ae0f-308db3fbf7eb",
"customerName": "Viocular",
"enduserName": "Toyletry",
"productId": 3,
"productName": "sit",
"createdBy": "Callahan",
"created": "2014-10-28",
"expires": "2011-01-11"
},
{
"id": "fd223cf3-7f1b-4afb-bccf-cf1907a33334",
"customerName": "Genekom",
"enduserName": "Chorizon",
"productId": 3,
"productName": "ipsum",
"createdBy": "Calhoun",
"created": "2013-09-12",
"expires": "2011-02-27"
}
]
],
/**
* a function that filters the "results" array based on a "searchTerm"
*/
filterResults = searchTerm => results.reduce((r, group) => {
const f = group.filter(({customerName}) => customerName.includes(searchTerm));
/** only push NON empty groups (sub arrays) to the final array */
f.length && r.push(f);
return r;
}, []);
/** test "fileterResults" function */
console.log(filterResults("Farmex"));
.as-console-wrapper {
max-height: 100%!important;
}

Accessing Array Object property in ES6,

my friend, I hope you are all fine over there. Please, I would like to know how I can access some specific value within an array object! I am designing an app with Redux, and I was able to retrieve the first array object value but the last array object which is more complex than the previous is giving headache. Can someone help me out. Below is the Object:
{
[
[{
"id": 1,
"full_name": "jack",
"email": "carl#gmail.com",
"phone": "2123309",
"dob": "2008-06-12",
"location": "VAUGHAN",
"user_id": 1,
"created_at": "2021-10-02T09:10:04.000000Z",
"updated_at": "2021-10-02T12:16:57.000000Z"
}],
[{
"id": 1,
"price": "432.00",
"order_type": "Car Parking",
"currency": "USD",
"paid": 0,
"amount_paid": "432.00",
"overdue": "0.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T09:10:26.000000Z",
"updated_at": "2021-10-02T09:46:00.000000Z"
}, {
"id": 2,
"price": "2500.00",
"order_type": "Ramp",
"currency": "USD",
"paid": 0,
"amount_paid": "2030.00",
"overdue": "470.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T09:48:07.000000Z",
"updated_at": "2021-10-02T10:14:22.000000Z"
}, {
"id": 9,
"price": "893.00",
"order_type": "Shipping",
"currency": "CAD",
"paid": 0,
"amount_paid": "765.00",
"overdue": "128.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T10:46:45.000000Z",
"updated_at": "2021-10-02T10:54:06.000000Z"
}, {
"id": 21,
"price": "250.00",
"order_type": "Storage rent",
"currency": "USD",
"paid": 0,
"amount_paid": "0.00",
"overdue": "250.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-03T08:33:13.000000Z",
"updated_at": "2021-10-03T08:33:13.000000Z"
}]
]
}
To access FULL_NAME I did :
client.data.map((client) => client[0].full_name)
if I try to access a second array with [1] it gives me cannot access that property.
Now there are two things I wish to do here, get the length of the second array, and be able to loop over that array. Also, how can I access a specific value in that object, let assume for instance I want to retrieve AMOUNT_PAID in object 2. Any idea please?
You can map over the array at index [1], and use .length to get the length of the outcome array.
const data = [
[{
"id": 1,
"full_name": "jack",
"email": "carl#gmail.com",
"phone": "2123309",
"dob": "2008-06-12",
"location": "VAUGHAN",
"user_id": 1,
"created_at": "2021-10-02T09:10:04.000000Z",
"updated_at": "2021-10-02T12:16:57.000000Z"
}],
[{
"id": 1,
"price": "432.00",
"order_type": "Car Parking",
"currency": "USD",
"paid": 0,
"amount_paid": "432.00",
"overdue": "0.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T09:10:26.000000Z",
"updated_at": "2021-10-02T09:46:00.000000Z"
}, {
"id": 2,
"price": "2500.00",
"order_type": "Ramp",
"currency": "USD",
"paid": 0,
"amount_paid": "2030.00",
"overdue": "470.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T09:48:07.000000Z",
"updated_at": "2021-10-02T10:14:22.000000Z"
}, {
"id": 9,
"price": "893.00",
"order_type": "Shipping",
"currency": "CAD",
"paid": 0,
"amount_paid": "765.00",
"overdue": "128.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-02T10:46:45.000000Z",
"updated_at": "2021-10-02T10:54:06.000000Z"
}, {
"id": 21,
"price": "250.00",
"order_type": "Storage rent",
"currency": "USD",
"paid": 0,
"amount_paid": "0.00",
"overdue": "250.00",
"client_id": 1,
"user_id": 1,
"created_at": "2021-10-03T08:33:13.000000Z",
"updated_at": "2021-10-03T08:33:13.000000Z"
}]
]
const result = data[1].map(x => x.amount_paid);
const resultLength = result.length;
console.log("Result: ", result);
console.log("Length: ", resultLength);

How to Correcly Filter Through Array

I am trying to compare two arrays but it is not filtering correctly. I am trying to add users, my function compares the ID and StaffID and if the StaffID is not in the current user array it should set the state of new user so they can be added.
export default function AddUserDropdown({onChange}) {
useEffect(() => {
getUsersToAdd();
}, []);
const [state, setState] = React.useState({
open: false,
name: '',
users: [],
id: null,
});
const [user, setUser] = React.useState({
newUsers: []
})
const getUsersToAdd = () => {
axios.all([
axios.get('/updateUserList'),
axios.get('/userInformation')
])
.then(axios.spread((newUserBox, currentUserBox) => {
let newUserIds = [];
let currentUserIds = [];
for (let newUser of currentUserBox.data){
newUserIds.push(newUser.id);
}
for (let user of newUserBox.data) {
if (!newUserIds[user.staffID]) {
currentUserIds.push(user);
}
}
setUser({...user, newUsers: currentUserIds });
}));
}
// ...
};
// ...
};
When the axios calls request userinformation endpoint it returns this
[
{
"id": 1,
"firstName": "Elton",
"lastName": "Frederick",
"departmentId": 1,
"admin": true,
"hasApproval": false,
"position": "Developer",
"vh5given": 31,
"vh5rec": 280,
"profilePic": "https://www.travelplannersinternational.com/wp-content/uploads/2019/12/Elton.jpg",
"password": "abc234"
},
{
"id": 2,
"firstName": "Julio",
"lastName": "Probando",
"departmentId": 1,
"admin": false,
"hasApproval": true,
"position": "Lead Dev",
"vh5given": 11,
"vh5rec": 339,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Julio_.jpg?lossy=1&strip=1&webp=1",
"password": "abc232"
},
{
"id": 3,
"firstName": "Corey",
"lastName": "Chris",
"departmentId": 2,
"admin": false,
"hasApproval": false,
"position": "Customer Service",
"vh5given": 14,
"vh5rec": 167,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/09/Corey.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 4,
"firstName": "Daisy",
"lastName": "Ramos",
"departmentId": 3,
"admin": false,
"hasApproval": false,
"position": "ATC",
"vh5given": 22,
"vh5rec": 202,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Daisy_.jpg?lossy=1&strip=1&webp=1",
"password": "abc321"
},
{
"id": 7,
"firstName": "Air Car Hotel",
"lastName": "Nunca",
"departmentId": 4,
"admin": false,
"hasApproval": false,
"position": "",
"vh5given": 0,
"vh5rec": 25,
"profilePic": "profile.jpg",
"password": "abc123"
},
{
"id": 8,
"firstName": "Jenn",
"lastName": "Lee",
"departmentId": 4,
"admin": false,
"hasApproval": false,
"position": "Vp Of Sales",
"vh5given": 0,
"vh5rec": 0,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Jenn2_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 9,
"firstName": "Reyna",
"lastName": "Pagan",
"departmentId": 5,
"admin": false,
"hasApproval": false,
"position": "Agent Support Manager",
"vh5given": 0,
"vh5rec": 20,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Reyna_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 10,
"firstName": "Ameilia",
"lastName": "Rodriguez",
"departmentId": 6,
"admin": false,
"hasApproval": false,
"position": "Human Resources",
"vh5given": 0,
"vh5rec": 5,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Amelia_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
}
]
These are the users that have been added.
When the updateUserList endpoint is called it returns:
[
{
"staffID": 1,
"dept": "Junior Web Developer",
"email": "manasaN#tpionline.com",
"name": "manasa",
"password": "$2y$10$/zYS7OhzwdLOi6Slzc3Rv.aJFJALiY0y1J6MjnLCN24GmZ3rMHWUS"
},
{
"staffID": 2,
"dept": "Web Developer",
"email": "juliof#tpionline.net",
"name": "Julio Fajardo",
"password": "$2y$10$MphAC8aRY2uzs1ZERZDn9uvCqK1/1nd7t0KukEkvGbx5Y4van.Da6"
},
{
"staffID": 3,
"dept": "Fake Title",
"email": "johnf#tpionline.com",
"name": "John Fester",
"password": "$2y$10$/oa/ESQmhhc5WvxrQKoUU.Pj5sM3gZY5FccilGfCUL5eyeOU5IDSa"
},
{
"staffID": 5,
"dept": "Fake Title",
"email": "fakeguy#gmail.net",
"name": "Test",
"password": "$2y$10$VWnnw5gRTN2absWos04fsOixW6TjOepNa3n0v/7ybFqsFZL8oPiJm"
},
{
"staffID": 6,
"dept": "Conf room",
"email": "conf2#gmail.com",
"name": "Conf 1st floor",
"password": "$2y$10$KAZa1k2Sd/rg6dnVeqw4duB/XbAhcVXP.Fze6Zle3ZhcMaRphloG."
},
{
"staffID": 8,
"dept": "Fake Title",
"email": "newguy#gmail.net",
"name": "New guy",
"password": ""
},
{
"staffID": 9,
"dept": "Fake Title",
"email": "nguy#gmail.net",
"name": "New Guy2",
"password": ""
},
{
"staffID": 12,
"dept": "Test ADD",
"email": "cristinab#tpionline.com",
"name": "Cristina Bermudez",
"password": "$2y$10$92I6fSJY6OW001caJJmeReHnaeF5tdHBjWHBmoCvX1RnfhTspjpBa"
},
{
"staffID": 30,
"dept": "Erwing",
"email": "erwingh#tpionline.com",
"name": "Erwing Hernandez",
"password": "$2y$10$RWgOBbUHojgmyk3behYhd.kzdFEiH.6BBaxn4B070pS5q5Gf3ZYEa"
}
]
What I need to accomplish is that if the there is no current user whose ID equals the staff ID it should be set in the state so i can add this user. With the data above the users that should be added should be
have the staff ID of: 5, 6, 12,30.
Right Now My functions returns:
0: {staffID: 8, dept: "Fake Title", email: "newguy#gmail.net", name: "New guy", password: ""}
1: {staffID: 9, dept: "Fake Title", email: "nguy#gmail.net", name: "New Guy2", password: ""}
2: {staffID: 12, dept: "Test ADD", email: "cristinab#tpionline.com", name: "Cristina Bermudez", password: "$2y$10$92I6fSJY6OW001caJJmeReHnaeF5tdHBjWHBmoCvX1RnfhTspjpBa"}
3: {staffID: 30, dept: "Erwing", email: "erwingh#tpionline.com", name: "Erwing Hernandez", password: "$2y$10$RWgOBbUHojgmyk3behYhd.kzdFEiH.6BBaxn4B070pS5q5Gf3ZYEa"}
let currentUserIds = currentUserBox.map(user => user.id)
let newUsers = newUserBox.filter(newUser => !currentUserIds.includes(newUser.staffID))
newUsers is the array you want.
The code would look something like this:
let currentUserBox = [{
"id": 1,
"firstName": "Elton",
"lastName": "Frederick",
"departmentId": 1,
"admin": true,
"hasApproval": false,
"position": "Developer",
"vh5given": 31,
"vh5rec": 280,
"profilePic": "https://www.travelplannersinternational.com/wp-content/uploads/2019/12/Elton.jpg",
"password": "abc234"
},
{
"id": 2,
"firstName": "Julio",
"lastName": "Probando",
"departmentId": 1,
"admin": false,
"hasApproval": true,
"position": "Lead Dev",
"vh5given": 11,
"vh5rec": 339,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Julio_.jpg?lossy=1&strip=1&webp=1",
"password": "abc232"
},
{
"id": 3,
"firstName": "Corey",
"lastName": "Chris",
"departmentId": 2,
"admin": false,
"hasApproval": false,
"position": "Customer Service",
"vh5given": 14,
"vh5rec": 167,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/09/Corey.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 4,
"firstName": "Daisy",
"lastName": "Ramos",
"departmentId": 3,
"admin": false,
"hasApproval": false,
"position": "ATC",
"vh5given": 22,
"vh5rec": 202,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Daisy_.jpg?lossy=1&strip=1&webp=1",
"password": "abc321"
},
{
"id": 7,
"firstName": "Air Car Hotel",
"lastName": "Nunca",
"departmentId": 4,
"admin": false,
"hasApproval": false,
"position": "",
"vh5given": 0,
"vh5rec": 25,
"profilePic": "profile.jpg",
"password": "abc123"
},
{
"id": 8,
"firstName": "Jenn",
"lastName": "Lee",
"departmentId": 4,
"admin": false,
"hasApproval": false,
"position": "Vp Of Sales",
"vh5given": 0,
"vh5rec": 0,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Jenn2_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 9,
"firstName": "Reyna",
"lastName": "Pagan",
"departmentId": 5,
"admin": false,
"hasApproval": false,
"position": "Agent Support Manager",
"vh5given": 0,
"vh5rec": 20,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Reyna_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
},
{
"id": 10,
"firstName": "Ameilia",
"lastName": "Rodriguez",
"departmentId": 6,
"admin": false,
"hasApproval": false,
"position": "Human Resources",
"vh5given": 0,
"vh5rec": 5,
"profilePic": "https://388616.smushcdn.com/941012/wp-content/uploads/2019/03/Amelia_.jpg?lossy=1&strip=1&webp=1",
"password": "abc123"
}
]
let newUserBox = [{
"staffID": 1,
"dept": "Junior Web Developer",
"email": "manasaN#tpionline.com",
"name": "manasa",
"password": "$2y$10$/zYS7OhzwdLOi6Slzc3Rv.aJFJALiY0y1J6MjnLCN24GmZ3rMHWUS"
},
{
"staffID": 2,
"dept": "Web Developer",
"email": "juliof#tpionline.net",
"name": "Julio Fajardo",
"password": "$2y$10$MphAC8aRY2uzs1ZERZDn9uvCqK1/1nd7t0KukEkvGbx5Y4van.Da6"
},
{
"staffID": 3,
"dept": "Fake Title",
"email": "johnf#tpionline.com",
"name": "John Fester",
"password": "$2y$10$/oa/ESQmhhc5WvxrQKoUU.Pj5sM3gZY5FccilGfCUL5eyeOU5IDSa"
},
{
"staffID": 5,
"dept": "Fake Title",
"email": "fakeguy#gmail.net",
"name": "Test",
"password": "$2y$10$VWnnw5gRTN2absWos04fsOixW6TjOepNa3n0v/7ybFqsFZL8oPiJm"
},
{
"staffID": 6,
"dept": "Conf room",
"email": "conf2#gmail.com",
"name": "Conf 1st floor",
"password": "$2y$10$KAZa1k2Sd/rg6dnVeqw4duB/XbAhcVXP.Fze6Zle3ZhcMaRphloG."
},
{
"staffID": 8,
"dept": "Fake Title",
"email": "newguy#gmail.net",
"name": "New guy",
"password": ""
},
{
"staffID": 9,
"dept": "Fake Title",
"email": "nguy#gmail.net",
"name": "New Guy2",
"password": ""
},
{
"staffID": 12,
"dept": "Test ADD",
"email": "cristinab#tpionline.com",
"name": "Cristina Bermudez",
"password": "$2y$10$92I6fSJY6OW001caJJmeReHnaeF5tdHBjWHBmoCvX1RnfhTspjpBa"
},
{
"staffID": 30,
"dept": "Erwing",
"email": "erwingh#tpionline.com",
"name": "Erwing Hernandez",
"password": "$2y$10$RWgOBbUHojgmyk3behYhd.kzdFEiH.6BBaxn4B070pS5q5Gf3ZYEa"
}
]
let currentUserIds = currentUserBox.map(user => user.id)
let newUsers = newUserBox.filter(newUser => !currentUserIds.includes(newUser.staffID))
console.log(newUsers)
I would like to show you some example how to do it:
const array1 = [{
"id": 1,
"firstName": "One"
},
{
"id": 3,
"firstName": "Three"
},
{
"id": 5,
"firstName": "Five"
}
];
const array2 = [{
"staffID": 2,
"firstName": "Staff Two"
},
{
"staffID": 3,
"firstName": "Staff Three"
},
{
"staffID": 4,
"firstName": "Staff Four"
},
{
"staffID": 7,
"firstName": "Staff Seven"
}
];
const filtered = array1.filter(one => array2.filter(two => one.id !== two.staffID).length > 0);
console.log(filtered);

How to identify extracted obj file from response of autodesk model derivative API?

In Model Derivative API (OBJ Extraction using DbIds), I retrieved OBJ URN using API. As Response shows below, it returns all children's URN for obj, mtl, and its zip. How do we identify the recent extraction as every child does have its own guid?
I have attached whole response JSON. What I am looking for is the second obj file which has extracted using several dbids like "17,19,21,22,23...". The first child obj was created long ago. How do I differentiate the new obj. As GUID's are different for every node. How do I identify which GUID.obj belongs to my desired extraction.
** Edited **
I am looking for identifying extracted wavefronts object files( not objectids and name which gets from metadata). Suppose if I extracted 2 object files from one model, then after completion of object file geometry extraction job, 6 file gets generated and store in bucket.
first .obj (guid = /output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.obj)
first .mtl
first .zip
second .obj
second .mtl
second .zip
Every file does have different GUID.Type as name. and those guid's are random and never shown while calling of extraction API or while getting its progress.
these are shown in below JSON file. Now suppose I extracted 10 different object files from one model. that means in bucket 30 new file URN will be generated.
And it is getting very hard to identify.
The Solution could have been if I extract obj geometry from model, I should get that particular obj, mtl, zips guid. IF I am getting only 3 ids then I can map those and download it from bucket.
What is happening now is I am getting all obj's guid (suppose 30 ) after calling get manifest GET :urn/manifest . And I am not understanding what obj file belong to which extraction.
{
"type": "manifest",
"hasThumbnail": "true",
"status": "success",
"progress": "complete",
"region": "US",
"urn": "dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA",
"version": "1.0",
"derivatives": [{
"name": "rme_advanced_sample_project.nwd",
"hasThumbnail": "true",
"status": "success",
"progress": "complete",
"outputType": "svf",
"children": [{
"guid": "763d96f1-0812-451d-b3a1-a51a27eba53b",
"name": "rme_advanced_sample_project.rvt",
"hasThumbnail": "true",
"role": "3d",
"viewableID": "rme_advanced_sample_project.rvt",
"progress": "complete",
"useAsDefault": true,
"status": "success",
"type": "geometry",
"children": [{
"guid": "1e172e73-2305-4eb8-9954-eeab8217a8d3",
"name": "Default",
"hasThumbnail": "true",
"role": "3d",
"camera": [-86.09573364257812, -79.89456176757812, 139.12220764160156, 70.56798553466797, 76.76915740966797, -17.541505813598633, 0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1.664323329925537, 0.785398006439209, 1, 0],
"useAsDefault": true,
"status": "success",
"type": "view",
"children": [{
"guid": "f2054c5f-10b8-457b-a927-23b69107dcd7",
"role": "thumbnail",
"mime": "image/png",
"resolution": [100, 100],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_100.png",
"type": "resource"
}, {
"guid": "20625548-d014-4d29-8e50-4d61a1759a60",
"role": "thumbnail",
"mime": "image/png",
"resolution": [200, 200],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_200.png",
"type": "resource"
}, {
"guid": "48675a6a-f2ec-4748-b22c-200b72cd06a8",
"role": "thumbnail",
"mime": "image/png",
"resolution": [400, 400],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0_400.png",
"type": "resource"
}]
}, {
"guid": "77850512-9e8b-4d09-bb1a-45706ad5b7e6",
"name": "3D View",
"hasThumbnail": "false",
"role": "viewable",
"progress": "0% complete",
"status": "success",
"type": "folder",
"children": [{
"guid": "ebf9f756-6cfa-4858-9787-e3af9c8424c3",
"name": "3D Duct & Equipment",
"role": "3d",
"camera": [61.56271743774414, 38.53883743286133, 9.783880233764648, 59.46215057373047, 40.639404296875, 7.683313846588135, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 227.96743774414062, 1],
"status": "success",
"type": "view"
}, {
"guid": "54d5a270-f330-4446-a482-1079312d8518",
"name": "Main Electrical Distribution",
"role": "3d",
"camera": [91.54497528076172, -63.42673110961914, -34.64605712890625, 46.680015563964844, 38.5232048034668, -66.7026596069336, -0.11140129715204239, 0.25314533710479736, 0.9609928131103516, 1, 45, 342.1146545410156, 1],
"status": "success",
"type": "view"
}, {
"guid": "2c6938f2-c052-4195-93d0-adc7af1cb965",
"name": "3D Plumbing",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "1b3f6ae4-beb6-478c-9cfe-b83bf371141d",
"name": "Room 53 3D Fire Protection",
"role": "3d",
"camera": [735.119384765625, -538.998779296875, 662.6300048828125, 98.2931900024414, 97.82740020751953, 25.80381202697754, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 368.90972900390625, 1],
"status": "success",
"type": "view"
}, {
"guid": "45811cc4-79ed-421b-82b2-6c8548d1507e",
"name": "WSHP 2-3 System View",
"role": "3d",
"camera": [108.588134765625, 117.7073974609375, 54.383365631103516, 102.33130645751953, 123.9642333984375, 48.12653350830078, -0.40824830532073975, 0.40824830532073975, 0.8164966106414795, 1, 45, 333.1808776855469, 1],
"status": "success",
"type": "view"
}, {
"guid": "8c1402a9-6af6-47af-af0d-2c025ca26109",
"name": "Plumbing Isometric - Domestic Water",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "9dcc0f6a-fc2c-418f-8d08-c99b7afed337",
"name": "Plumbing Isometric - Sanitary Waste",
"role": "3d",
"camera": [3.6063644886016846, -184.62478637695312, 180.24473571777344, 173.09983825683594, -2.4171712398529053, -0.014680136926472187, 0.39955270290374756, 0.42952418327331543, 0.8098559379577637, 1, 45, 461.8291931152344, 1],
"status": "success",
"type": "view"
}, {
"guid": "e3a2443a-7f4c-49dc-a41d-da067922ab04",
"name": "Typical Make Up Air Isometric Detail",
"role": "3d",
"camera": [0.8279496431350708, 187.99771118164062, 118.81455993652344, 100.31283569335938, 88.51282501220703, 19.32967758178711, 0.40824830532073975, -0.40824830532073975, 0.8164966106414795, 1, 45, 248.74505615234375, 1],
"status": "success",
"type": "view"
}, {
"guid": "915564b9-ed83-426e-88df-002dac32363b",
"name": "Typical Room WSHP",
"role": "3d",
"camera": [171.6078338623047, -3.038959264755249, 18.71452522277832, 90.31718444824219, 43.15993118286133, -21.66922950744629, -0.34472253918647766, 0.19591180980205536, 0.9180331826210022, 1, 45, 257.0640869140625, 1],
"status": "success",
"type": "view"
}, {
"guid": "12a3ef04-1364-4c23-af91-2679132e3848",
"name": "Toilet Room",
"role": "3d",
"camera": [196.7369842529297, -4.305071830749512, 109.12708282470703, 98.9510269165039, 86.86759948730469, 14.070858001708984, -0.42381933331489563, 0.3951563239097595, 0.8150022625923157, 1, 45, 359.9964294433594, 1],
"status": "success",
"type": "view"
}, {
"guid": "9a34ab86-dfdf-4516-a087-b8f9775435fe",
"name": "1st Level Slice",
"role": "3d",
"camera": [-76.2143325805664, -163.60708618164062, 175.46923828125, 111.73212432861328, 69.6202392578125, 11.465206146240234, 0.3013473451137543, 0.373949259519577, 0.8771269917488098, 1, 45, 313.0205993652344, 1],
"status": "success",
"type": "view"
}, {
"guid": "09effac0-27ac-4f02-b4d7-31ef18a57ef9",
"name": "{3D}",
"role": "3d",
"camera": [0.8279496431350708, 187.99771118164062, 118.81455993652344, 100.31283569335938, 88.51282501220703, 19.32967758178711, 0.40824830532073975, -0.40824830532073975, 0.8164966106414795, 1, 45, 358.7159118652344, 1],
"status": "success",
"type": "view"
}]
}, {
"guid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"role": "graphics",
"mime": "application/autodesk-svf",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/0.svf",
"type": "resource"
}]
}, {
"guid": "3b7195a7-17ec-4d80-b259-4e9df165f3fb",
"role": "Autodesk.CloudPlatform.PropertyDatabase",
"mime": "application/autodesk-db",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/0/properties.db",
"status": "success",
"type": "resource"
}]
}, {
"hasThumbnail": "false",
"status": "success",
"progress": "complete",
"outputType": "obj",
"children": [{
"guid": "22519ef5-9da5-35ca-bc70-b25b45e8f8fa",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.obj",
"status": "success",
"type": "resource"
}, {
"guid": "75401422-bb33-350a-aa10-05625504d6ca",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.mtl",
"status": "success",
"type": "resource"
}, {
"guid": "a4b9fb43-8525-3243-bde1-72797399e342",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [547, 924, 942, 977],
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/e72fa6b3-4fc2-3c86-8424-5d0755539c0d.zip",
"status": "success",
"type": "resource"
}, {
"guid": "1177e7ea-7fad-34b7-a7bd-23d70e4a62a8",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.obj"
}, {
"guid": "61acd067-4637-3549-9bd3-cd362a4fb93b",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.mtl"
}, {
"guid": "6c73254c-7bbf-312a-a481-aaeebdf53de3",
"type": "resource",
"role": "obj",
"modelGuid": "f9f4721d-9304-43c4-8c07-34cbcc5e79c7",
"objectIds": [17, 19, 21, 22, 23, 24, 25, 26, 27, 83, 84, 85, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 263, 264, 265, 268, 269, 270, 302, 303, 304, 320, 321, 322, 350, 351, 352, 370, 371],
"status": "success",
"urn": "urn:adsk.viewing:fs.file:dXJuOmFkc2sub2JqZWN0czpvcy5vYmplY3Q6ZXh0cmFjdC1hdXRvZGVzay1pby0yMDE3MnVvbm5paWJkd2t1Z25ydGVvZGFjN2FpeWhwdjdrd20vcm1lX2FkdmFuY2VkX3NhbXBsZV9wcm9qZWN0Lm53ZA/output/geometry/a08e65e7-082a-3ce1-8116-ae534c9f081d.zip"
}]
}]
}
Use GET :urn/metadata to obtain a list of model views:
{
"data": {
"type": "metadata",
"metadata": [
{
"name": "Scene",
"role": "3d",
"guid": "4f981e94-8241-4eaf-b08b-cd337c6b8b1f",
},
{
"name": "Sheet: A101",
"role": "2d",
"guid": "8e7c6bca-cfd1-290e-4b16-f3670169bb71"
}
]
}
}
Then use GET :urn/metadata/:guid to retrieve the object tree to identify your derivatives:
{
"data": {
"type": "objects",
"objects": [
{
"objectid": 1,
"name": "A5",
"objects": [
{
"objectid": 2,
"name": "Model",
"objects": [
{
"objectid": 3,
"name": "Bottom",
"objects": [
{
"objectid": 4,
"name": "Box"
}
]
},

Replace some objects and arrays using javascript?

I am using nodejs as server side, i got some of the json objects
This is my json array with objects
[
{
"id": 20,
"gsm": "123456789",
"firstName": "Mohamed",
"lastName": "Sameer",
"contactgroups": [
{
"contactId": 20,
"groupId": 14,
"group": {
"groupname": "Angular"
}
}
]
},
{
"id": 21,
"gsm": "987654321",
"firstName": "Ganesh",
"lastName": "Pandiyan",
"contactgroups": [
{
"contactId": 21,
"groupId": 14,
"group": {
"groupname": "Angular"
}
},
{
"contactId": 21,
"groupId": 15,
"group": {
"groupname": "React"
}
}
]
}
]
I want final output like this(See my groupname key):
[
{
"id": 20,
"gsm": "123456789",
"firstName": "Mohamed",
"lastName": "Sameer",
"contactgroups": [
{
"contactId": 20,
"groupId": 14,
"groupname": "Angular",
"group": {}
}
]
},
{
"id": 21,
"gsm": "987654321",
"firstName": "Ganesh",
"lastName": "Pandiyan",
"contactgroups": [
{
"contactId": 21,
"groupId": 14,
"groupname": "Angular",
"group": {}
},
{
"contactId": 21,
"groupId": 15,
"groupname": "React",
"group": {}
}
]
}
]
is it possible? to do, which is best map or reduce or lodash? any method?
I want to change the place of groupname and to remove the groupname from group object.
You can use array#map. This will return a new array with modified keys & values
var orgArray = [{
"id": 20,
"gsm": "123456789",
"firstName": "Mohamed",
"lastName": "Sameer",
"contactgroups": [{
"contactId": 20,
"groupId": 14,
"group": {
"groupname": "Angular"
}
}]
},
{
"id": 21,
"gsm": "987654321",
"firstName": "Ganesh",
"lastName": "Pandiyan",
"contactgroups": [{
"contactId": 21,
"groupId": 14,
"group": {
"groupname": "Angular"
}
},
{
"contactId": 21,
"groupId": 15,
"group": {
"groupname": "React"
}
}
]
}
]
var newArray = orgArray.map(function(item) {
return {
"id": item.id,
"gsm": item.gsm,
"firstName": item.firstName,
"lastName": item.lastName,
// an IIFE which will create the new contactgroups
"contactgroups": (function() {
return item.contactgroups.map(function(item2, index) {
return {
"contactId": item2.contactId,
"groupId": item2.groupId,
"groupname": item2.group.groupname,
"group": {}
}
})
}())
}
})
console.log(newArray);

Categories

Resources