J
J
Jirafek2022-02-01 22:28:53
typescript
Jirafek, 2022-02-01 22:28:53

How to iterate over nested object?

I have such an object

const aside = {
    well: {
        name: "Колодец",
        costs: "200/250/300",
        src: "../images/shop/wells/well-01.png"
    },
    depot: {
        name: "Склад",
        costs: "150/200/250",
        src: "../images/shop/depots/depot-01.png"
    },
    cage: {
        name: "Клетка",
        costs: "100/150/200",
        src: "../images/shop/cages/cage-01.png"
    }
};

Actually the question is how to go through each name , costs , src . Well, will an interface be needed for each and how will it generally look like for the entire object?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex Karo, 2022-02-02
@Zraza

And what is the difficulty?
Options:
1) 2 nested for...in loops https://developer.mozilla.org/ru/docs/Web/JavaScri...
2) Option 1 via the .map method, if converted to an array via Object .keys / Object.entries
3) You can write a recursive traversal, but with limited nesting - why?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question