Back

Push vs Assign Array to an Index , JS | React

Copy Below Code View As A Text File Show Text Only Show API Edit Code
                            

Push = if you want to add any element to existing array you will do push method like const arr = ['First item', 'Second item', 'Third item']; arr.push('Fourth item'); console.log(arr); // ['First item', 'Second item', 'Third item', 'Fourth item'] Assign Whole Array : If you want to assign a complete to an index, inside an array you will do following. const mappingArr = { roleId: roleId, mappings: { moduleId: childModuleId, actionId: {} }, }; mappingArr.mappings.actionId = newChecked;