Skip to content

Instantly share code, notes, and snippets.

@squalvj
Last active September 22, 2018 05:49
Show Gist options
  • Save squalvj/09940e38df90781bb3d6afb61bdf4414 to your computer and use it in GitHub Desktop.
Save squalvj/09940e38df90781bb3d6afb61bdf4414 to your computer and use it in GitHub Desktop.
Validate every element inside object inside array
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