September 2017
Intermediate to advanced
216 pages
6h 8m
English
Another common structure is deeply-nested maps. Let's imagine that you want to filter keys, including nested keys, by flattening the nested map structure:
const myMap = Map.of( 'first', 1, 'second', Map.of( 'third', 3, 'fourth', 4, 'fifth', Map.of( 'sixth', Map.of( 'seventh', 7 ) ) ));console.log('myMap', myMap.toJS());// -> { first: 1,// -> second: {// -> third: 3,// -> fourth: 4,// -> fifth: {// -> sixth: { seventh: 7 } } } }myMap .toSeq() .flatten() .filter((v, k) => k.startsWith('f')) .forEach((v, k) => console.log(k, v)); // -> first 1 // -> fourth 4
Here, we are able to find all nested values whose key started with 'f'. One of the keys—'fifth'—starts with 'f', but it doesn't appear in the results. When you flatten ...
Read now
Unlock full access