Javascript 导出多维数组会导致某些值为空

问题描述 投票:0回答:1

我正在编写一个练习 React 应用程序,其中我使用名为 data.js 的单独文件导出原始数组

export const data = [
{
    type:"multiple",
    difficulty:"easy",
    category:"Entertainment: Film",
    question:"The Queen song `A Kind Of Magic` is featured in which 1986 film?",        
    correct_answer:"Highlander",
    incorrect_answers:["Flash Gordon","Labyrinth","Howard the Duck"]
    
},
{
    type:"multiple",
    difficulty:"easy",
    category:"Entertainment: Film",
    question:"Who plays Jack Burton in the movie "Big Trouble in Little China?"",
    correct_answer:"Kurt Russell",
    incorrect_answers:["Patrick Swayze","John Cusack","Harrison Ford"]
},
{
    type:"multiple",
    difficulty:"easy",
    category:"Entertainment: Film",
    question:"Which of these films is NOT set in Los Angeles?",
    correct_answer:"RoboCop",
    incorrect_answers:["Blade Runner","The Terminator","Predator 2"]
},
{
    type:"multiple",
    difficulty:"easy",
    category:"Entertainment: Film",
    question:"Who wrote and directed the 1986 film 'Platoon'?",
    correct_answer:"Oliver Stone",
    incorrect_answers:["Francis Ford Coppola","Stanley Kubrick","Michael Cimino"]
},
{
    type:"multiple",
    difficulty:"easy",
    category:"Entertainment: Film",
    question:"This movie contains the quote, "I feel the need ... the need for speed!"",
    correct_answer:"Top Gun",
    incorrect_answers:["Days of Thunder","The Color of Money","Cocktail"]
}

]

但是,当我将文件导入我的应用程序时,如下所示

import {data} from "./assets/data.jsx"
import Question from "./Question"

console.log(data)

in Correct_answers 是空数组

enter image description here

但是奇怪的是,当我将不正确的数组:重命名为不正确的数组时,值就会正确导出。我似乎无法理解这种行为,因为我认为它应该第一次正确导出数组。

非常感谢任何有关此问题的帮助。

谢谢你

里维

javascript reactjs multidimensional-array export
1个回答
0
投票

您的文件名为

data.js
,但您正在导入
data.jsx
。应用程序可能有另一个带有
data.jsx
的文件,其中字段
incorrect_answers
为空

© www.soinside.com 2019 - 2024. All rights reserved.