Working with Recursive function, I want to return an object with key, value. But I am returning an array with keys and values inside.
let path = (myObj: any) => {
if (myObj) {
const isObject = (val: any) =>
typeof val === 'object' && !Array.isArray(val)
//Path Name
const addDelimiter = (a: any, b: any) => (a ? `${a}.schema.${b}` : b)
const paths = (obj = {}, head = '') => {
return Object.entries(obj || {}).reduce(
(product, [key, value]: any) => {
let fullPath = addDelimiter(head, key)
if (isObject(value)) {
return product.concat(paths(value, fullPath))
} else {
)
return product.concat({ [fullPath]: value })
}
},
[]
)
}
returns
0: {name.schema.data: "lollololol"}
1: {name.schema.info: "John"}
I want outcome:
{
name.schema.data: "lollololol"
name.schema.info: "John"
}