I have a question
I have an array group like this :
myArray = { tab1 : [], tab2 : [], tab3 : [], tab4 : [] }
I want to always keep my first tab (tab1) and to keep an additionnal tab using an index (which value is between 2 and 4)
For example : if my index value is 2, I want to keep the tab2 and obtain this :
myArray = { tab1 : [], tab2 : [] }
Thanks
2
Answers
You can use
Array.prototype.reduce
to do something like thisHere
Object.entries(myArray)
will transform your object into an 2d array of key / value