I have properties in an Array and an Object. I need to remove the properties, which are not in the Array allowedFields.
Actually, I need to create separate Object with only allowed fields from response data. Please suggest a solution.
let allowedFields = [
"organization_id",
"organization_name",
"payload.offer.application_id",
"payload.offer.user_id",
"id",
"candidate_id",
];
Below is the Object values:
let data = {
organization_id: 4002400004,
organization_name: "Velocity Global Integration Sandbox",
action: "offer_updated",
payload: {
offer: {
id: 4524843004,
application_id: 31948577004,
user_id: 4123647004,
version: 1,
sent_on: null,
resolved_at: "2022-05-19T06:21:25.084Z",
start_date: "2022-05-17",
notes: null,
job_id: 4298940004,
offer_status: "Accepted",
},
resume: {
name: "manikandan",
},
},
};
Object only have the properties which exists in the allowedFields Array. Expecting output below:
let output = {
organization_id: 4002400004,
organization_name: "Velocity Global Integration Sandbox",
payload: {
offer: {
application_id: 31948577004,
user_id: 4123647004,
},
},
};