I would appreciate if you will help me with the next problem I have. The following view shows a table with a `button` that dynamically adds new rows to the table and each row is predefined with a `select` type control.
[![enter image description here](https://i.stack.imgur.com/573vF.png)](https://i.stack.imgur.com/573vF.png)

I use [Select2](https://select2.org/) to give it the style that can see the `select`

My question is the following, how can I get that every time I add a new row to the table, when opening the `select`, just show me the `options` that have not been previously selected.I use jQuery.
Thank you very much in advance

**EDIT 1**
What I tried:

```
$(document).on('select2:opening', 'select[name^="table2"]', function() {

            let input = $(this);

            let initialOptions = [];

            let selectedOptions = [];

            $(input.find('option').each(function(id, option) {
                initialOptions.push(option);
            }));

            $('select[name^="table2"] option:selected').each(function() {
                selectedOptions.push($(this).val());
            });

            initialOptions.splice($.inArray(selectedOptions, initialOptions), 1 );
        });

```

**EDIT 2**

Guys, nothing you've commented on has worked, it's frustrating, so far I only have 2 array of objects:

```
$(document).on('select2:opening', 'select[name^="table2"]', function() {

            let input = $(this);

            let initialOptions = [];

            let selectedOptions = [];

            $(input.find('option').each(function() {
                initialOptions.push($(this));
            }));

            $('select[name^="table2"] option:selected').each(function() {
                selectedOptions.push($(this));
            });

            console.log(initialOptions);
            console.log(selectedOptions);
        });

```

the console returns me these 2 arrays:

```
Array(24) [ {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, … ]

Array(3) [ {…}, {…}, {…} ]

```

expanded:

```
24) […]
​
0: Object [ option
 ]
​
1: Object [ option
 ]
​
2: Object [ option
 ]
​
3: Object [ option
 ]
​
4: Object [ option
 ]
​
5: Object [ option
 ]
​
6: Object [ option
 ]
​
7: Object [ option
 ]
​
8: Object [ option
 ]
​
9: Object [ option
 ]
​
10: Object [ option
 ]
​
11: Object [ option ]

```

and the second

```
(3) […]
​
0: Object [ option
 ]
​
1: Object [ option
 ]
​
2: Object [ option
 ]
​
length: 3
​
<prototype>: Array []

```

I need to remove from the first array all the objects that are in the second, except one that meets the condition that the value is equal to a certain number.