[Ramda] Create a Query String from an Object using Ramda's toPairs function
In this lesson, we'll use Ramda's toPairs function, along with map, join, concatand compose to create a reusable function that will convert an object to a querystring.
const R = require('ramda'); const {map, join, concat, compose, toPairs} = R; const obj = { page: 2, limit: 6, type: 'movies' }; const createQs = compose( concat('?'), // ?page=2&limit=6&type=movies join('&'), // page=2&limit=6&type=movies map(join('=')), // [ 'page=2', 'limit=6', 'type=movies' ] toPairs // [ [ 'page', 2 ], [ 'limit', 6 ], [ 'type', 'movies' ] ] ); const result = createQs(obj); console.log(result);

浙公网安备 33010602011771号