D
D
da_da_ya_neudachnik2022-03-09 16:01:16
JavaScript
da_da_ya_neudachnik, 2022-03-09 16:01:16

User selection in JSON?

Guys, tell me, please, how to make a user choice in JSON. I need to select a user from an array, but the problem is that the user is in multiple conversations. How to make user selection of a specific conversation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
defriz, 2022-03-09
@da_da_ya_neudachnik

you need to have a conversation base and an array with users in it, then you need to find the conversation base by its id and then also find the user from the array.
I will make an example:

const base = [
  {
    "chatId": 1,
    "users": [
      {
        "id": 123
      }
    ]
  }
]; // типа JSON-база

// представим, что объект сообщения ВК называется message

const peer = base.filter(x => x.chatId === message.chatId)[0];
const user = peer.users.filter(x => x.id === message.senderId)[0];
console.log(user);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question