Imagine a situation where users can select multiple items and remove them. This calls for two arrays:
- One containing checkbox values (checked status and index)
- The other holding the actual items that need to be filtered based on the checked values' index.
Here are the two arrays and the expected result using lodash:
const checked = [
{
index: 0,
checked: false
},
{
index: 1,
checked: true // note that the second index is checked so we need to filter out the second item from the items array.
},
];
const items = [
{
title: 'This is title 1',
description: 'This is description 1',
end_date: '2018-03-12 14:00:00',
location: '3577 Rue de Bullion, Montréal, QC H2X 3A1, Canada',
room: 401,
start_date: '2018-03-12 13:00:00',
},
{
title: 'This is title 2',
description: 'This is description 2',
end_date: '2018-03-12 14:00:00',
location: '3577 Rue de Bullion, Montréal, QC H2X 3A1, Canada',
room: 401,
start_date: '2018-03-12 13:00:00',
}
];
const result = [
{
title: 'This is title 1',
description: 'This is description 1',
end_date: '2018-03-12 14:00:00',
location: '3577 Rue de Bullion, Montréal, QC H2X 3A1, Canada',
room: 401,
start_date: '2018-03-12 13:00:00',
}
];