-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathfind.js
More file actions
23 lines (20 loc) · 728 Bytes
/
find.js
File metadata and controls
23 lines (20 loc) · 728 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
Example of find() API
---------------------
You just need to pass a path string to the find()
API to get the desired result.
If you want to traverse to multi-level hierarchy,
just separate the properties by '.'.
*/
const jsonQ = require('../index.js');
let Q = new jsonQ(__dirname + '/data.json');
//To get a direct property 'cities' from Json
const products = Q.find('cities');
console.log('-------- Printing Prodcuts---------');
console.log(products);
// Resetting the instance to initial state
// because the previous find() query changed it internal state
Q = Q.reset();
const firstProductsName = Q.find('cities.0.name');
console.log('-------- Printing First Prodcuts Name ---------');
console.log(firstProductsName);