I've imported an array from another file but I can't access any of its elements. The array is imported but when I try and access an element using [0] it returns undefined
standList.js | How I exported the array:
exports.stands = ["Star Platinum","Crazy Diamond","Golden Experience"]
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.`);
},
};
output:
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.
CodePudding user response:
Try exporting and requiring this way:
const stands = ["Star Platinum","Crazy Diamond","Golden Experience"];
module.exports = {
stands
}
const { stands } = require('../data/standList.js');