Check deep object property and find duplicate value

I use the following code to find if there is duplicate value in property path:

return new Promise((resolve, reject) => {             var data = [];             Parser.parse()              //configObj is the value from the screen shot                 .then((configObj) => {                     configObj.forEach((providers) => {                         _.each(providers, (provider) => {                             _.each(provider, (entry) => {                                 for (var prop in entry) {                                     if (_inArray(entry[prop].path, data)) {                                         return reject(new Error(`Duplicate path ${entry[prop].path}`));                                     }                                     data.push(entry[prop].path);                                 }                             })                         })                     })                     resolve("validObject");                 }, err => {                     reject(err);                 }); 

For example, this is the object configObj and as you can see I need to find duplicate in object 'replace' and object 'save' for the value in field 'path'; if they have the same value, it rejects with error; otherwise it resolves the promise. Is there is more elegant way to write it?

Check deep object property and find duplicate value

In this example, the path is different (test2 & command1) but it can also be the same.

Replay

Category: javascript Time: 2016-07-29 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.167 (s). 12 q(s)