Current result has this:
[
['Cycling','Chess'],
['Cycling','Pilates'],
['Cycling','Elevate'],
['Cycling','Kundalini'],
['Cycling','Scrabble'],
['Cycling','Crossword'],
['Cycling','Darning'],
['Running','Ashtanga'],
['Running','Poker'],
['Running','Sudoku'],
['Running','Sewing'],
['Running','Jump'],
['Boxing','Mushin'],
['Boxing','Tai'],
['Boxing','Tae'],
['Boxing','1000'],
['Boxing','Transient'],
['Boxing','Walking'],
['Strength','Flow'],
['Strength','Tantric'],
['Strength','Quigong'],
['Strength','Active']
]
Split the array so that only the following remains:
['Chess'],
['Pilates'],
['Elevate'],
['Kundalini'],
['Scrabble'],
['Crossword'],
['Darning'],
['Ashtanga'],
['Poker'],
['Sudoku'],
['Sewing'],
['Jump'],
['Mushin'],
['Tai'],
['Tae'],
['1000'],
['Transient'],
['Walking'],
['Flow'],
['Tantric'],
['Quigong'],
['Active']
Split only appears to work on 1 dimension arrays so I’m looking for an alternative. Numpty has an hsplit function but unable to find an equivalent for Javascript. Thanks
3
Answers
Use
map
:arr.map(subarr => [subarr[1]])
, though I don’t see why you want one-element lists.arr.map(subarr => subarr[1])
, producing a list of strings, is probably more useful.you can use the
map
method, here’s sample code:You can use reduce to create a dictionary, so you "deduplicate" data on the same iteration. This code only works for arrays with 2 items. You can easily iterate over that array so you can use it with arrays of any size