R
Reactiflux

snowberb – 14-24 Jun 22

snowberb – 14-24 Jun 22

S⛄Snowberb⛄6/22/2023
I need to check for falsy or empty array props in an object, and I do not know how to make it so it checks all nested props. Any guidance? I've done this for now but it won't work if the prop has a nested object with more props
export const objectPropsNotEmpty = (obj: Record<PropertyKey, unknown>) => {
for (const prop of Object.values(obj)) {
if (prop instanceof Array) {
if (!prop.length) {
return false;
}

continue;
}

if (isNil(prop)) {
return false;
}
}

return true;
};
export const objectPropsNotEmpty = (obj: Record<PropertyKey, unknown>) => {
for (const prop of Object.values(obj)) {
if (prop instanceof Array) {
if (!prop.length) {
return false;
}

continue;
}

if (isNil(prop)) {
return false;
}
}

return true;
};
recursion?
export const objectPropsNotEmpty = (obj: Record<PropertyKey, unknown>) => {
for (const prop of Object.values(obj)) {
if (typeof prop === 'object' && prop !== null) {
if (!objectPropsNotEmpty(prop)) {
return false;
}
}

if (prop instanceof Array) {
if (!prop.length) {
return false;
}

continue;
}

if (isNil(prop)) {
return false;
}
}

return true;
};
export const objectPropsNotEmpty = (obj: Record<PropertyKey, unknown>) => {
for (const prop of Object.values(obj)) {
if (typeof prop === 'object' && prop !== null) {
if (!objectPropsNotEmpty(prop)) {
return false;
}
}

if (prop instanceof Array) {
if (!prop.length) {
return false;
}

continue;
}

if (isNil(prop)) {
return false;
}
}

return true;
};
UUUnknown User6/24/2023
2 Messages Not Public
Sign In & Join Server To View

Looking for more? Join the community!

R
Reactiflux

snowberb – 14-24 Jun 22

Join Server