Module for deleting repeated objects. The module considers romantic key and values and the visual structure.
Start:
- Install the dependency with
npm i --save unique-array-objects
- Import the library:
/*
* Use as function
*/
import uab from 'unique-array-objects';
var array = [
{
id: 1,
nome: 'Jhon'
},
{
id: 2,
nome: 'Jhon'
}, {
id: 1,
nome: 'Jhon'
},
{
id: 1,
nome: 'Jhon',
altura: 1.71
}
]
console.log(uab(array);
/**
* WILL RETURN:
*
* 0 => id: 1, nome: 'Jhon'
* 1 => id: 2, nome: 'Jhon'
* 2 => id: 1, nome: 'Jhon', altura: 1.71
*/
/*
* Use as Array.prototype
*/
import uab from 'unique-array-objects/prototype';
Array.prototype.remove = uab
var array = [
{
id: 1,
nome: 'Jhon'
},
{
id: 2,
nome: 'Jhon'
}, {
id: 1,
nome: 'Jhon'
},
{
id: 1,
nome: 'Jhon',
altura: 1.71
}
]
console.log(array.remove())
/*
* Use as middleware on Node
*/
router.get('/test', require('unique-array-objects/middle'), function (req, res) {
var array = [{
id: 1,
nome: 'Jhon'
},
{
id: 2,
nome: 'Jhon'
}, {
id: 1,
nome: 'Jhon'
},
{
id: 1,
nome: 'Jhon',
altura: 1.71
}
]
res.send(req.uac(array))
})