I am currently working on generating an array of objects from another array of objects that have nested arrays. The goal is to substitute the nested arrays with the key name followed by a dot. For instance:
const data = [ id: 5, name: "Something", obj: { lower: True, higher: False } ]
result = ["id", "name", "obj.lower", "obj.higher"]
I have been successful in extracting the nested keys and values, but I am facing difficulties in getting the objects from the array.
For example (expected result):
const data = [ id: 5, name: "Something", obj: { lower: True, higher: False } ]
const newData = [{id: 5}, {name: "Something"}, {obj.lower: True}, {obj.higher: False}]
I have tried the following approach:
getValues = object => Object.entries(object).flatMap(([k, v]) => {
if (typeof v !== "object") {
return {[k]: v}
}
return v && typeof v === 'object' ? this.getKeys(v).map(s => `${k}.${s}`) : [k];
});
Next, I will be comparing these filtered array of objects with user data that looks like this:
export const requiredKeys = {
data: {
id: null,
status: null,
summary: null,
// "updated_by.id": null,
// "updated_by.firstname": null,
// "updated_by.lastname": null,
// "updated_by.username": null,
// "updated_by.blocked": null,
// "pillars.pillarsType": null,
// "student.created_by": null,
// state: null,