map-attack
Turns Maps into Arrays, Turns Arrays into Maps
Install
npm install map-attack --save
Usage
var mapAttack = require('map-attack');
mapAttack( Map||Array, indexByString)
Converting Array to Map
mapAttack([
{
id : '1',
value : 'hello'
},
{
id : '2',
value : 'world'
},
{
id : '3',
value : '!'
}
],'id');
Result :
//Results in a Map indexed by your second parameter
{
1 : {
id : '1',
value : 'hello'
},
2 : {
id : '2',
value : 'world'
},
3 : {
id : '3',
value : '!'
}
}
Converting Map to Array
mapAttack({
1 : {
value : 'hello'
},
2 : {
value : 'world'
},
3 : {
value : '!'
}
}, 'id')
Result :
//Results in a Array with ids by your second parameter
[
{
id : '1',
value : 'hello'
},
{
id : '2',
value : 'world'
},
{
id : '3',
value : '!'
}
]
Notes:
This library uses:
So any syntax those accept for setting/getting values from objects you can use for your index by parameter