1

How to convert an array to an object like {}
The result I receive in the code below is an array

currently the result is [ { result: result} ] but I want to convert it to { result:result }

I tried fromEntries, But it shows result: { undefined: undefined }

Here is the Code:

module.exports = {
    name: "wki",
    aliases: [],
    run: async (client, message, args, color) => {
        const query = args.join(" ")

        wikia.search(query).then(results => {
            console.log(results)
            const obj = Object.fromEntries(results);
            console.log(obj);

        });
    }
}
0

1 Answer 1

2

If the array only contains single element, you can just access it using index:

module.exports = {
    name: "wki",
    aliases: [],
    run: async (client, message, args, color) => {
        const query = args.join(" ")

        wikia.search(query).then(results => {
            console.log(results)
            const obj = results[0];
            console.log(obj);

        });
    }
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.