Last active
September 22, 2018 05:49
-
-
Save squalvj/09940e38df90781bb3d6afb61bdf4414 to your computer and use it in GitHub Desktop.
Validate every element inside object inside array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let pOC = [ | |
{ | |
fullName: '', | |
type: { | |
name: '' | |
}, | |
email: '', | |
mobileNo: '', | |
officeNo: '', | |
}, | |
{ | |
fullName: '', | |
type: { | |
name: '' | |
}, | |
email: '', | |
mobileNo: '', | |
officeNo: '', | |
}, | |
] | |
//will return 'true' if everything pass in the function | |
let pocValidate = pOC.map(e => { | |
let k = true; | |
Object.keys(e).forEach(l => { | |
if (e[l] == '') k = false | |
if (e[l].name == '') k = false | |
}) | |
return k | |
}).every(e => e) | |
//let isAllPocValidate = pocValidate.every(e => e) <<< this expression is same as the top expression | |
//console.log('ispoc', isAllPocValidate) | |
console.log('poc', pocValidate) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment