S
S
Sanders Rocket2020-04-21 20:39:13
Node.js
Sanders Rocket, 2020-04-21 20:39:13

How to make js request result in one line?

let noft = await vk.call('messages.getConversationMembers', {
          peer_id: msg.message.peer_id,
          fields: 'id, first_name', 
          group_id: 193658885
        });
        noft.items.forEach(element => {
          if (element.member_id > 0){
            console.log(element.member_id)
            // messagesend('[id' + element.member_id + '|@]')
          }
        });

we have such code
vzAwZBI.png
we have such result of request.
Now the question is how to do everything in one line, and then substitute messagesend('id'..'|@]') at the request of the form

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Klimenko, 2020-04-21
@sandersik

const noft = await vk.call('messages.getConversationMembers', {
    peer_id: msg.message.peer_id,
    fields: 'id, first_name', 
    group_id: 193658885
});

const longString = noft.items.filter(item => (item.member_id > 0))
                             .map(item => `[id${item.member_id}|@]`)
                             .join(' ');

console.log(longString);
// [id590120892|@] [id299403203|@] [id102021723|@]

// ...

D
de1m, 2020-04-21
@de1m

I haven't tested, but something like this

let noft = await vk.call('messages.getConversationMembers', {
          peer_id: msg.message.peer_id,
          fields: 'id, first_name', 
          group_id: 193658885
        });
        noft.items.forEach(element => {
          if (element.member_id > 0){
            console.log("[id" + element.member_id.join('') + '|@]')
            // messagesend('[id' + element.member_id + '|@]')
          }
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question