Skip to content

Instantly share code, notes, and snippets.

@HamishWHC
Created August 15, 2020 06:06
Show Gist options
  • Save HamishWHC/a12aff18c79afe74095e6d87293d0d4f to your computer and use it in GitHub Desktop.
Save HamishWHC/a12aff18c79afe74095e6d87293d0d4f to your computer and use it in GitHub Desktop.
Check that channel ID is part of game.
var game = {
otherKeys: "values",
channel: 187382131313,
channels: {
controlChannel: 311313123123,
otherChannel: 13131313123,
channelList1: [
12112321313,
12312312311
],
channelList2: [
2183213213,
132213231132
]
}
}
var channelIds = Object.values(game.channels) // Array of both channel IDs and more arrays.
/*
[
311313123123,
13131313123,
[
12112321313,
12312312311
],
[
2183213213,
132213231132
]
]
*/
var flattened = channelIds.flat() // Array of channel IDs
/*
[
311313123123,
13131313123,
12112321313,
12312312311,
2183213213,
132213231132
]
*/
var isChannel = channelIdToCheck in flattened; // True or false value.
// Inline version:
channelId in Object.values(game.channels).flat()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment