Help with Array boolean in Beatmix project

Hello,

I have a question related to the Beatmix project, but. I do not understand why it returns only one array result [false] and does not change the one array object instead. Can anyone take a look?

let kicks = new Array(16).fill(false); let snares = new Array(16).fill(false); let hiHats = new Array(16).fill(false); let rideCymbals = new Array(16).fill(false); toggleDrum = (instrument, index) => { if (instrument === 'kicks' || instrument === 'snares' || instrument === 'hiHats' || instrument === 'rideCymbals') { let convertString = eval (instrument); return convertString.splice(index, 1, true) } } console.log(toggleDrum('kicks', 1));

If you add a console.log statement at the end, you will see that the element at index 1 of the kicks array is indeed true.

...Rest of code...

console.log(toggleDrum('kicks', 1));
// [ false ]

console.log(kicks);
// [ false, true,  false, false, false, false, false, false, 
//   false, false, false, false, false, false, false, false ]

As for why the first statement is logging [ false ], have a look at your toggleDrum function. The toggleDrum function is returning the return value of the splice method. Documentation is always a great resource for exploring the details of different methods and features of a programming language.

Documentation of the splice method: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

scrn1

:man_facepalming:

Thank you very much.