Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I get sibling value in JS object?

How can I get ‘Pivot Grid’, when I have 7? Is there method or can you help me with function?

WIDGET_TYPES = {

    PIVOT_GRID: {
        LABEL: 'Pivot Grid',
        ID: 7,
    },
    DATA_GRID: {
        LABEL: 'Grid',
        ID: 4,
    },
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

you can use Object.values and find

Object.values – will convert your object to array wiht next structure:

[{LABEL: 'Pivot Grid',ID: 7,}, ...]

after conversion you can apply find to new generated array.
In the find method you will pass your id(7) what need to find

then we need to take label from found element of array

const WIDGET_TYPES = {
    PIVOT_GRID: {
        LABEL: 'Pivot Grid',
        ID: 7,
    },
    DATA_GRID: {
        LABEL: 'Grid',
        ID: 4,
    },
};

const ID = 7;

const foundLabel = Object.values(WIDGET_TYPES).find(i => i.ID === ID)?.LABEL;

console.log('foundLabel: ', foundLabel)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading