Skip to content

Latest commit

 

History

History
44 lines (33 loc) · 1.15 KB

README.md

File metadata and controls

44 lines (33 loc) · 1.15 KB

De Nest to flat


Nest with objects; nest with arrays; deeply nest; we dont care! 😘

Print out all the keys,
Print out all the values.


... this project uses a recursive function.

Examples:

Deeply nested object, containing objects or arrays:

const obj = { a: 7, b: 2, c: {value:3} };
console.log(flattenAnything({ obj }))
// output: '{"keys":["obj.a","obj.b","obj.c.value"],"values":[7,2,3]}'

// having output in this way you could search obj and get the value from output.

const arr = [7, undefined,  {value: undefined, value2: 4}, 1, 2, 3, 4];
console.log( flattenAnything({ arr }) )
// output: {"keys":["arr[0]","arr[2].value2","arr[3]","arr[4]","arr[5]","arr[6]"],"values":[7,4,1,2,3,4]}


// example retrieval:
console.log( { result: obj[ output.keys[1] ] } )
// { result: 4 }

Setup

git clone https://github.com/MichaelDimmitt/De-Nest.git
cd De-Nest
npm test
node runner

Sorry here, just looking for a good tutorial

no problem!

run this script to get the output:

for d in ./tutorialsForOthers/* ; do (echo && echo "$d" && node $d); done

or node <specific tutorialfile.js>