[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 mapjoinconcatand 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: ,
limit: ,
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);
上一篇:Java反射机制 —— 简单了解


下一篇:Java-对象排序