Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

118
Views
How to access array from another file Next Js

I'm creating a Quiz App. There are two pages takeQuiz.js and result.js. I want to collect mcqs data from takeQuiz.js in result.js.I using router.replace() so user can't go back one they submit quiz.
takeQuiz.js

mcqsData = [
{quesId:1,correct:'Option A',selectedOption:'Option C'},
{quesId:1,correct:'Option C',selectedOption:'Option B'},
{quesId:1,correct:'Option D',selectedOption:'Option D'},
]

How can I access this array in result.js?. I tried import data from './takeQuiz.js' but it return undefined

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are missing the export statement in front of your array. Without it, the import statement has nothing to grab.

export mcqsData = [
{quesId:1,correct:'Option A',selectedOption:'Option C'},
{quesId:1,correct:'Option C',selectedOption:'Option B'},
{quesId:1,correct:'Option D',selectedOption:'Option D'},
]

then in your main result.js file, import the name of your array. import {mcqsData} from './takeQuiz.js'

More info can be found here: https://developer.mozilla.org/en-US/docs/web/javascript/reference/statements/export

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!