Javascript library notes

Some notes on a few popular javascript libraries.


How to get startDate and endDate?

var range = $("#range").daterangepicker();
var start ="daterangepicker").startDate;
var end ="daterangepicker").endDate;



var data = [{label: '4/1', value: 10}, {label: '4/2', value: 14}];
var labels =, function(item) { return item.label; });
var values =, function(item) { return item.value; });

It is especially useful when preparing data for some chart libraries.

convert array to object

var data = [{value: 0, name: 'Working'}, {value: 1, name: 'Idle'}];
var result = _.chain(data).keyBy('value').mapValues('name').value();
//The result will be {0: 'Working', 1: 'Idle'}


How to pass array when using $.get

$.get("/api", {"name[]": ["George", "Jacky"]}, function(data) {});

If you are using Spring MVC for the server side, here is the relative code to receive multiple parameters.

public YourResponseEntity api(@RequestParam("name") String[] names) {
  //deal with names


comments powered by Disqus