Mencoba meminimalkan kode JS dan ingin meningkatkan kecepatan kinerja di JS
const obj = {
visible: {
test1: false,
test2: false,
test3: false,
test4: false,
test5: false,
test6: false,
test7: false,
test8: false,
},
required: {
test1: false,
test2: false,
test3: false,
test4: false,
test5: false,
test6: false,
test7: false,
test8: false,
},
};
const fields = [
{ field: 'test1', required: true },
{ field: 'test2', required: true },
{ field: 'test3', required: true },
{ field: 'test4' },
{ field: 'test5' },
];
fields.forEach(({ field, required }) => {
const key = field; // `${field}${number}`;
obj.visible[key] = true;
SAMER SAEID