can we get an object from a single object key value in javascript?

Simply use find

const val = [
    {
        id: '1',
        name: 'A',
    },
    {
        id: '2',
        name: 'B',
    },
];
const res = val.find(obj => obj.id === '2');
console.log(res);

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top