JSFiddle - React, Tailwind, and code Playground

by Aubrey Taylor

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

JavaScript

var json = {
  page: 1,
  pageSize: 100,
	foo: [{name: "1", value: "1", foo: "other"}, {name: "2", value: "2", foo: "other"}], 
  bar: [{name: "3", value: "3", foo: "other"}, {name: "4", value: "4", foo: "other"}], 
  baz: [{name: "5", value: "5", foo: "other"}, {name: "6", value: "6", foo: "other"}]};
var props = ["foo", "bar"];
var memo = {};

function toDict(memo, data) {
  memo[data.name] = data.value;
  return memo;
}

var result = _.chain(json)
	.pick(props)
  .tap(function(result){console.log(result)})
  .toArray()
  .tap(function(result){console.log(result)})
  .flatten()
  .reduce(toDict, memo)
  .extend({pageSize: json.pageSize, page: json.page})
  .value();
  
console.log(result);