Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // getTypeStats
- const getTypeStats = (obj) => {
- let newObj = {};
- let keys = Object.values(obj);
- let strings = 0;
- let numbers = 0;
- let objects = 0;
- let arrays = 0;
- for (const key of keys) {
- if((typeof key) === 'string') {
- strings++;
- newObj['strings'] = strings;
- } else if ((typeof key) === 'number') {
- numbers++;
- newObj['numbers'] = numbers;
- } else if ((typeof key) === 'object' && key !== null && !Array.isArray(key)) {
- objects++;
- newObj['objects'] = objects;
- } else if ((Array.isArray(key))){
- arrays++;
- newObj['arrays'] = arrays;
- }
- }
- return newObj;
- }
Advertisement
Add Comment
Please, Sign In to add comment