This question has already been answered:

There is such a function:

function msg() { if(!message.content && message.attachments.first()) return {files:[message.attachments.first().proxyURL]} else if(message.content && !message.attachments.first()) return message.content else return message.content, {files:[message.attachments.first().proxyURL]} } 

The problem is that all the conditions work correctly, but in the third condition the function returns only what is written after the comma.
How do I return in full:

 message.content, {files:[message.attachments.first().proxyURL]} 

instead:

 {files:[message.attachments.first().proxyURL]} 

Reported as a duplicate at Grundy. javascript Jun 12 '18 at 7:06 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    2 answers 2

    Operator "comma" .
    How - depends on what you need to return: an array - wrap in [] , an object - {} .
    You cannot return multiple values ​​in JS.

    • Then "[message.content, {files: [message.attachments.first (). ProxyURL]}]" will be displayed, but I don’t need these square brackets, what should I do? - KiiDii
    • What? Do you understand what return means? What is displayed? - user207618 9:16 pm
    • I mean that return should return me "message.content, {files: [message.attachments.first (). ProxyURL]}", not "[message.content, {files: [message.attachments.first ( ) .proxyURL]}] ". - KiiDii
    • In JS there is no structure значение, значение . - user207618
    • Maybe there is then an option for another check done? For the variant with variables doesn't roll either ... - KiiDii

    Decided this way:

     function msg() { if(!message.content && message.attachments.first()) return [{files:[message.attachments.first().proxyURL]}] else if(message.content && !message.attachments.first()) return [message.content] else return [message.content, {files:[message.attachments.first().proxyURL]}] } let [content, file] = msg() 

    Instead of returning an array, only after the third condition - I now return an array after each condition. This solved my problem!

    Thank you for helping answer the above!