简体   繁体   中英

removing objects from an array using filter [ Javascript ]

Hey i'm trying to remove objects from an array using filter but i can't seem to get it working. .

It works when i remove the e.serverID !== '8:0:0' from the filter but i'm trying to filter it with the server ids.

I was just wondering if anyone had any ideas why?

 var MyUsers = [{ id: 1, url: 'https://LinkHere.com/#1', authorID: 12345, username: 'MyUserName', isadmin: true, serverID: '8:0:0', serverIP: 'MyServerIP1' }, { id: 2, url: 'https://LinkHere.com/#2', authorID: 12345, username: 'MyUserName', isadmin: true, serverID: '8:0:0', serverIP: 'MyServerIP1' }, { id: 3, url: 'https://LinkHere.com/#3', authorID: 67890, username: 'TestUser', isadmin: false, serverID: '8:0:0', serverIP: 'MyServerIP2' } ] console.log('My user befor filter', MyUsers); MyUsers = MyUsers.filter(e => e.authorID !== 12345 && e.username !== 'MyUserName' && e.serverID !== '8:0:0'); setTimeout(console.log('My user after filter', MyUsers), 1000)

Hey i'm trying to remove objects from an array using filter but i can't seem to get it working. .

It works when i remove the e.serverID !== '8:0:0' from the filter but i'm trying to filter it with the server ids.

I was just wondering if anyone had any ideas why?

 var MyUsers = [{ id: 1, url: 'https://LinkHere.com/#1', authorID: 12345, username: 'MyUserName', isadmin: true, serverID: '8:0:0', serverIP: 'MyServerIP1' }, { id: 2, url: 'https://LinkHere.com/#2', authorID: 12345, username: 'MyUserName', isadmin: true, serverID: '8:0:0', serverIP: 'MyServerIP1' }, { id: 3, url: 'https://LinkHere.com/#3', authorID: 67890, username: 'TestUser', isadmin: false, serverID: '8:0:0', serverIP: 'MyServerIP2' } ] console.log('My user befor filter', MyUsers); MyUsers = MyUsers.filter(e => e.authorID !== 12345 && e.username !== 'MyUserName' && e.serverID !== '8:0:0'); setTimeout(console.log('My user after filter', MyUsers), 1000)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM