Contents
- Creating Extractor instance and test data
- Getting single values
2.1. ... if path exists
2.2. ... if path doesn't exist
2.3. ... with checking of path existence - Getting arrays of values
3.1. ... if path exists
3.2. ... if path doesn't exist
3.3. ... with checking of path existence - More examples
4.1. Getting of array elements
4.2. Getting a defined property of array elements (objects)
4.3. Getting a defined property of array elements (objects) that are deeply nested - Using filters
5.1. Getting names of countries with population bigger than 300 millions
5.2. Getting names of cities where name starts with ‘S’
5.3. Getting cities with population bigger than 20 millions in countries with population bigger than 1 billion
1. Creating Extractor instance and test data
const Extractor = ;let extractor = ; let data = countries: name: 'Australia' population: 24641662 cities: name: 'Sydney' population: 5029768 name: 'Melbourne' population: 4725316 name: 'Canberra' population: 435019 name: 'Brazil' population: 211243220 cities: name: 'São Paulo' population: 12038175 name: 'Rio de Janeiro' population: 6498837 name: 'Salvador' population: 2938092 name: 'China' population: 1388232693 cities: name: 'Shanghai' population: 24152700 name: 'Beijing' population: 21700000 name: 'Guangzhou' population: 14043500 name: 'United States' population: 326474013 cities: name: 'New York' population: 8537673 name: 'Los Angeles' population: 3976322 name: 'Chicago' population: 2704958 country_codes: 'AU' 'BR' 'CN' 'US' count: 4;
extractor;console; // 4
2.2. ... if path doesn't exist
extractor;console; // undefined
2.3. ... with checking of path existence
extractor;let response = extractor; if response console; // 4
extractor;console; // ['AU', 'BR', 'CN', 'US']
3.2. ... if path doesn't exist
extractor;console; // []
3.3. ... with checking of path existence
extractor;response = extractor; if response console; // ['AU', 'BR', 'CN', 'US']
4.1. Getting of array elements
extractor;console; // [ { name: 'Australia', population: 24641662, cities: [ ... ] },// { name: 'Brazil', population: 211243220, cities: [ ... ] },// { name: 'China', population: 1388232693, cities: [ ... ] },// { name: 'United States', population: 326474013, cities: [ ... ] } ]
4.2. Getting a defined property of array elements (objects)
extractor;console; // [ 'Australia', 'Brazil', 'China', 'United States' ]
4.3. Getting a defined property of array elements (objects) that are deeply nested
extractor;console; // [ 'Sydney', 'Melbourne', 'Canberra', 'São Paulo',// 'Rio de Janeiro', 'Salvador', 'Shanghai', 'Beijing',// 'Guangzhou', 'New York', 'Los Angeles', 'Chicago' ]
5.1. Getting names of countries with population bigger than 300 millions
extractor;extractor;extractor;console; // [ 'China', 'United States' ]
5.2. Getting names of cities where name starts with 'S'
extractor;extractor;extractor;console; // [ 'Sydney', 'São Paulo', 'Salvador', 'Shanghai' ]
extractor;extractor;extractor;extractor;console; // [ { name: 'Shanghai', population: 24152700 },// { name: 'Beijing', population: 21700000 } ]