Hi i have array of objects like below,
const arr_obj = [
{
children: [{}],
type: "type1",
updated: "somevalue",
},
{
children: [{}],
type: "type2",
updated: "somevalue",
},
]
now i want to create a new array of object that will have each object as in arr_obj and also add new property "disabled" which is boolean value set to true if type is equal to "type2" if not set to false.
so the expected output is like below
const new_obj = [
{
children: [{}],
type: "type1",
updated: "somevalue",
disabled: false,
},
{
children: [{}],
type: "type2",
updated: "somevalue",
disabled: true,
},
]
I have tried like below
const new_obj = React.useMemo(() => {
arr_obj.map((arr => ({
...arr,
disabled: arr?.type !== "type2" ? false : true,
}))
}, [arr_obj]
);
but when i log new_obj this is undefined. could someone help me with this. I am new to programming. thanks.