Answer the question
In order to leave comments, you need to log in
How to get primitive properties of nested objects recursively?
link
How to make a return here to return the found values?
function getProp(o) {
for(var prop in o) {
if(typeof(o[prop]) === 'object') {
getProp(o[prop]);
} else {
//return o[prop];
console.log(o[prop]);
}
}
}
Answer the question
In order to leave comments, you need to log in
const getPrimitiveProps = (obj) =>
Object.entries(obj).reduce((acc, [ k, v ]) => ({
...acc,
...(v instanceof Object ? getPrimitiveProps(v) : { [k]: v }),
}), {});
const getPrimitiveProps = (obj) =>
Object.assign({}, ...Object.entries(obj).map(([ k, v ]) =>
v instanceof Object ? getPrimitiveProps(v) : { [k]: v }
));
function getProp(o) {
var result = [];
for(var prop in o) {
if(typeof(o[prop]) === 'object') {
result = result.concat(getProp(o[prop]));
}
}
return result;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question