[go: up one dir, main page]

objectarray-pullmap

0.0.9 • Public • Published

objectarray-pullmap

NPM

Pull part of an Object Array to a Map.

var pullmap = require('objectarray-pullmap');
// pullmap(<object array>, <keys>, <values>)
 
var a = [
  {'n': 'Notable', 'p': 'Psuedocode', 'm': 'Mashups'},
  {'n': 'Noiseless', 'p': 'Peaceful', 'm': 'Morning'},
  {'n': 'Norwegian', 'p': 'Peat', 'm': 'Moss'},
  {'n': 'Noiseless', 'p': 'Party', 'm': 'Machine'}
];
 
pullmap(a, ['n'], ['p', 'm']);
// Map(4) {
//   {"n": "Notable"} => {"p": "Psuedocode", "m": "Mashups"},
//   {"n": "Noiseless"} => {"p": "Peaceful", "m": "Morning"},
//   {"n": "Norwegian"} => {"p": "Peat", "m": "Moss"},
//   {"n": "Noiseless"} => {"p": "Party", "m": "Machine"}
// }
 
pullmap(a, 'n', ['p']);
// Map(4) {
//   "Notable" => {"p": "Psuedocode"},
//   "Noiseless" => {"p": "Peaceful"},
//   "Norwegian" => {"p": "Peat"},
//   "Noiseless" => {"p": "Party"}
// }
 
pullmap(a, 'n', 'p');
// Map(4) {
//   "Notable" => "Psuedocode",
//   "Noiseless" => "Peaceful",
//   "Norwegian" => "Peat",
//   "Noiseless" => "Party"
// }
 
pullmap(a);
// Map(4) {
//   {"n": "Notable", "p": "Psuedocode", "m": "Mashups"} => {"n": "Notable", "p": "Psuedocode", "m": "Mashups"},
//   {"n": "Noiseless", "p": "Peaceful", "m": "Morning"} => {"n": "Noiseless", "p": "Peaceful", "m": "Morning"},
//   {"n": "Norwegian", "p": "Peat", "m": "Moss"} => {"n": "Norwegian", "p": "Peat", "m": "Moss"},
//   {"n": "Noiseless", "p": "Party", "m": "Machine"} => {"n": "Noiseless", "p": "Party", "m": "Machine"}
// }

Readme

Keywords

Package Sidebar

Install

npm i objectarray-pullmap

Weekly Downloads

0

Version

0.0.9

License

MIT

Last publish

Collaborators

  • wolfram77