Cannot figure out, why the object innerMain
is getting smaller on every select change even though it gets redefined with object main
’s structure in the beginning of the every call to the trig()
function:
let innerMain = main;
var main = {
1: 0,
2: 0,
3: 0,
4: 0
};
$('#sel').on('change', function(){
trig($(this));
});
function trig(th = false){
let innerMain = main;
delete innerMain[th.val()];
console.log(innerMain);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select id="sel">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
<div id="result"></div>