1
i have the following list of objects but need to filter only user...
let msg = [{ _id: 5cef45879e78602774e921d0,
to: '5ce82f0deee6dc458a20b21e',
from: '5ce82f0deee6dc458a20b21e',
text: '5',
type: 'text',
user:
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.2',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559184735135 },
channel: '/geral',
createdAt: 1559184775656 },
{ _id: 5cef45789e78602774e921cf,
to: '5ce82f0deee6dc458a20b21e',
from: '5ce82f0deee6dc458a20b21e',
text: '4',
type: 'text',
user:
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.2',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559184735135 },
channel: '/geral',
createdAt: 1559184760319 },
{ _id: 5cef406c52c9ec1e37065be7,
to: '5ce82f0deee6dc458a20b21e',
from: '5ce82f0deee6dc458a20b21e',
text: '3',
type: 'text',
user:
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
channel: '/geral',
createdAt: 1559183468769 },
{ _id: 5cef406952c9ec1e37065be6,
to: '5ce82f0deee6dc458a20b21e',
from: '5ce82f0deee6dc458a20b21e',
text: '2',
type: 'text',
user:
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
{ _id: 5cef406352c9ec1e37065be5,
to: '5ce82f0deee6dc458a20b21e',
from: '5ce82f0deee6dc458a20b21e',
text: '1',
type: 'text',
user:
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
channel: '/geral',
createdAt: 1559183459121 } ]
Então rodei let x = msg.map(res => res.user) dai consegui..
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.2',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559184735135 },
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.2',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559184735135 },
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
Then I circled that code to get the repeaters out...
let unic = x.filter(function (a) {
return !this[JSON.stringify(a)] &&
(this[JSON.stringify(a)] = true);
}, Object.create(null))
I received :
[ { id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.1',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559183392625 },
{ id: '5ce82f0deee6dc458a20b21e',
name: 'usuario4.2',
display: 'usuario4',
descript: 'usuario4',
avatar: 'blazer2.png',
createdAt: 1559184735135 } ]
Only that I would like it only to show what has the most current date that has id = id
I have no idea how to do this.... someone could help...
Thanks, Salvo...
– Sidiclei F. Almeida