Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let person = {
- firstName: "Steven",
- lastName: "Queen",
- age: 60,
- address: {
- street: "12 Port str",
- city: "Portland",
- },
- interests: ["writing", "drinking"],
- };
- const getTypeStats = (obj) => {
- let newObj = { ...obj };
- let resultObj = {
- strings: 0,
- numbers: 0,
- objects: 0,
- arrays: 0,
- };
- for (let x in obj) {
- if (Array.isArray(x)) {
- resultObj.arrays += 1;
- }
- if (typeof obj[x] === "string") {
- resultObj.strings += 1;
- }
- if (typeof obj[x] === "number") {
- resultObj.numbers += 1;
- }
- if (typeof obj[x] === "object") {
- resultObj.objects += 1;
- }
- }
- return newObj;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement