discord.js: Imported array not displaying expected values

I've been facing an issue with accessing elements from an imported array. Even though the array is successfully imported, attempting to access its elements using [0] results in undefined.

Here's how I exported the array in standList.js:

exports.stands = ["Star Platinum", "Crazy Diamond", "Golden Experience"]

This is how I'm trying to access it:

const stands = require('../data/standList.js');

module.exports = {
    name: 'interactionCreate',
    async execute(interaction, client) {

        if(interaction.isButton()){
            
            if (interaction.customId === 'standarrow'){
                var stand = stands[0];
                console.log(stands);
                console.log(stands[0]);
                console.log(stand);
                await interaction.reply("You have awakened the power of *" + stand + "*!");}  
        }
        
        console.log(`${interaction.user.tag} in #${interaction.channel.name} triggered an interaction.`);
    },
};

The output shows:

KomiKage in #testzone triggered an interaction.
Killjoy :  | testzone | Thu Oct 27 2022 13:41:51 GMT+0200 (Central European Summer Time)
{ stands: [ 'Star Platinum', 'Crazy Diamond', 'Golden Experience' ] }
undefined
undefined
KomiKage in #testzone triggered an interaction.

Answer №1

Attempt a different approach by exporting and requiring like so:

const characters = ["Goku","Vegeta","Piccolo"];

module.exports = {
   characters
}
const { characters } = require('../data/characterList.js');

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Choose components identified by a dot

If I have a simple script that displays an element based on the option selected, how can I handle periods in the values? For instance: <select id="my-selector"> <option value="cat.meow">Cat</option> <option value="dog.bark"> ...

Why isn't my callback working? Can anyone help me figure out what I did wrong?

I'm currently facing an issue while making an asynchronous call to Redis and attempting to utilize a callback to inform async.js about the completion of the query. I am consistently receiving an error message stating "callback is not a function". Can ...

Resizing a d3 graph for various screen resolutions

Looking to create a dynamic dashboard in Angular, I found a code snippet for a gauge chart at this link. Here is an example of how my HTML file appears: <div fxLayout="row" fxLayoutAlign="space-around center" > <div fxFlex='33%'> ...

Switching PHP include on an HTML page using JavaScript

I've been attempting to modify the content of the div with the ID "panel_alumno" using a JavaScript function that triggers when a button is clicked. My goal is to display a different table each time the button is pressed, but so far, I haven't be ...

Tips for displaying lesser-known checkboxes upon clicking a button in Angular

I have a form with 15 checkboxes, but only 3 are the most popular. I would like to display these 3 by default and have an icon at the end to expand and collapse the rest of the checkboxes. Since I'm using Angular for my website, I think I can simply ...

Sorting numbers in an array using PHP

Currently, I am working on a project that requires arranging an array in such a way that no same numbers appear consecutively. For example, let's take $a = [4,1,2,1,3,4,4,4]. In this case, the number 4 appears consecutively. To avoid this, the desire ...

What are the differences between Sitecore Analytics and Adobe Analytics? How do they each utilize JavaScript

I have limited knowledge about Sitecore Analytics (with MongoDB) and I am curious if there exists a Javascript API that can be utilized for non-Sitecore websites. If so, could you please direct me to the relevant documentation? Additionally, any insights ...

Exporting a Component with React can be done in two ways: named exports and

There's a common syntax I've come across in various files: import React, {Component} from react; While I grasp the concept of named exports and default exports individually, I'm uncertain about how React manages this when exporting its cod ...

What is the optimal order for executing JavaScript, jQuery, CSS, and other controls to render an HTML page efficiently?

What are some recommended strategies for optimizing webpage loading speed? What key factors should be taken into consideration? ...

Having difficulty personalizing the email template on AWS SES

I am currently working on setting up a forgot password email system using AWS SES. Below is the template I have created: { "Template":{ "TemplateName": "forgotpasswrd", "SubjectPart": "Forgot ...

Transform an array of strings into properties of an object

Looking for a way to map an array to a state object in React? Here's an example: const array =["king", "henry", "died", "while", "drinking", "chocolate", "milk"] Assuming you have the following initial state: state = { options:{} } You can achieve ...

Guide to Updating Store State with API Data

My goal is to update my component state with data retrieved from an API using a getter in the store. Within the mounted() lifecycle hook, I call the getProducts() getter which is defined as: export const getters = { async getProducts() { axios.ge ...

Unusual outcome observed when inputting a random number into HTML using JavaScript

In my HTML file, I am trying to input a number within 50% of a target level into the "Attribute" field. Here is the code: <!DOCTYPE html> <html> <body> <input type = "number" name = "playerLevel" onchan ...

Why Does React Material-UI Switch Styling Keep Changing Sporadically?

Currently, I am trying to integrate a switch component from MUI into my code. Strangely enough, upon the initial page load, the switch appears exactly as it should - identical to the one displayed on the MUI site. However, upon reloading the page, it under ...

Assign a class to the element only when the second div also has a class

I am trying to create a functionality where I have a dropdown element (Li element) that receives an Active class when its parent div (button) is clicked. When the dropdown element has this class, I want to assign the same class to another div. If the dropd ...

Transform JSON data containing a variety of objects, such as strings and arrays, into a Map

Currently, I am attempting to transform a JSON object into a map object within Hive using the `brickhouse.udf.json.FromJsonUDF` library. The issue that I am facing is that my JSON object includes various types of values: strings and an array containing ot ...

Uploading files in React.js using Yii2 API

I am working with react.js (version 15) and I need to upload files using yii2 api. Here is my code: My component in react: import React, { Component } from 'react'; import Header from './Heaader'; /* global $ */ class New ...

Using inline SVG in a Vite production build

When utilizing Vite and Vue, my goal is to compile a single JavaScript file without creating an assets directory that includes SVG and GIF files during the build process. I want to achieve this without manually inserting the SVG code in a Vue JS file as a ...

What is the best way to verify changing input fields in vue.js?

Validation of input fields using vuelidate is essential. The input field in question is dynamic, as the value is populated dynamically with jsonData through the use of v-model. The objective: Upon blur, the goal is to display an error if there is one; ho ...

basic computation of whole and decimal values using jquery

I'm having trouble multiplying 2 values in my code where the quantity is an integer and credit price is a decimal number. However, when I run the script, nothing seems to happen. Can someone please help me identify and resolve this issue? Any insight ...