Pick a single item from an array

Usage no npm install needed!

<script type="module">
  import pickit from 'https://cdn.skypack.dev/pickit';



Build Status Code Climate Coverage Status Dependency Status devDependency Status

var pick = require('pickit');

var array = [
  {name: 'James', age: 36, siblings: 3},
  {name: 'Susan', age: 40, siblings: 2},
  {name: 'Noah', age: 4, siblings: 1}

// supply a callback
pick.max(array, function (x) {return x.age;}); // {name: 'Susan', ...}

// or a string property name
pick.max(array, 'siblings');                   // {name: 'James', ...}
pick.min(array, 'siblings')/                   // {name: 'Noah', ...}


pickit requires that Array.prototype.reduce be implemented (IE 9 or greater). A copy of the standard polyfill is included for your convenience (reduce-polyfill.js).