Skip to main content
Active reading [<https://www.youtube.com/watch?v=1Dax90QyXgI&t=17m54s>].
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

FewA few ways to do that...

1) 2 layersA two-layer for...in loop...

for (let key in validation_messages) { const vmKeys = validation_messages[key]; for (let vmKey in vmKeys) { console.log(vmKey + vmKeys[vmKey]); } } 

2) Using Object.key

Object.keys(validation_messages).forEach(key => { const vmKeys = validation_messages[key]; Object.keys(vmKeys).forEach(key => { console.log(vmKeys + vmKeys[key]); }); }); 

3) Recursive function

const recursiveObj = obj => { for(let key in obj){ if(!obj.hasOwnProperty(key)) continue; if(typeof obj[key] !== 'object'){ console.log(key + obj[key]); } else { recursiveObj(obj[key]); } } } 

And call it like:

recursiveObj(validation_messages); 

Few ways to do that...

1) 2 layers for...in loop...

for (let key in validation_messages) { const vmKeys = validation_messages[key]; for (let vmKey in vmKeys) { console.log(vmKey + vmKeys[vmKey]); } } 

2) Using Object.key

Object.keys(validation_messages).forEach(key => { const vmKeys = validation_messages[key]; Object.keys(vmKeys).forEach(key => { console.log(vmKeys + vmKeys[key]); }); }); 

3) Recursive function

const recursiveObj = obj => { for(let key in obj){ if(!obj.hasOwnProperty(key)) continue; if(typeof obj[key] !== 'object'){ console.log(key + obj[key]); } else { recursiveObj(obj[key]); } } } 

And call it like:

recursiveObj(validation_messages); 

A few ways to do that...

1) A two-layer for...in loop...

for (let key in validation_messages) { const vmKeys = validation_messages[key]; for (let vmKey in vmKeys) { console.log(vmKey + vmKeys[vmKey]); } } 

2) Using Object.key

Object.keys(validation_messages).forEach(key => { const vmKeys = validation_messages[key]; Object.keys(vmKeys).forEach(key => { console.log(vmKeys + vmKeys[key]); }); }); 

3) Recursive function

const recursiveObj = obj => { for(let key in obj){ if(!obj.hasOwnProperty(key)) continue; if(typeof obj[key] !== 'object'){ console.log(key + obj[key]); } else { recursiveObj(obj[key]); } } } 

And call it like:

recursiveObj(validation_messages); 
Source Link
Alireza
  • 105.5k
  • 27
  • 280
  • 173

Few ways to do that...

1) 2 layers for...in loop...

for (let key in validation_messages) { const vmKeys = validation_messages[key]; for (let vmKey in vmKeys) { console.log(vmKey + vmKeys[vmKey]); } } 

2) Using Object.key

Object.keys(validation_messages).forEach(key => { const vmKeys = validation_messages[key]; Object.keys(vmKeys).forEach(key => { console.log(vmKeys + vmKeys[key]); }); }); 

3) Recursive function

const recursiveObj = obj => { for(let key in obj){ if(!obj.hasOwnProperty(key)) continue; if(typeof obj[key] !== 'object'){ console.log(key + obj[key]); } else { recursiveObj(obj[key]); } } } 

And call it like:

recursiveObj(validation_messages);