objectarray-pullmap
v0.0.9
Published
Pull part of an Object Array to a Map.
Downloads
7
Readme
objectarray-pullmap
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"}
// }