improved loops in getValuesAtPath method

This commit is contained in:
Stéphane Campinas 2016-11-16 10:10:28 +00:00
parent 6a2bc0188c
commit 991864cdd3
No known key found for this signature in database
GPG key ID: 8272664236A42C2F

View file

@ -36,11 +36,11 @@ export default function (json, path) {
if (pathIndex >= path.length) {
if (element) {
if (element.constructor === Array) {
for (let i = 0; i < element.length; i++) {
if (element[i]) {
values.push(element[i]);
element.forEach(child => {
if (child) {
values.push(child);
}
}
});
} else {
values.push(element);
}
@ -50,9 +50,7 @@ export default function (json, path) {
getValues(element[path[pathIndex]], pathIndex + 1);
}
} else if (element.constructor === Array) {
for (let childi = 0; childi < element.length; childi++) {
getValues(element[childi], pathIndex);
}
element.forEach(child => getValues(child, pathIndex));
}
};