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

206
Views
How to import a variable from a js file

I want to import a array from a js file and it doesn't work. My code :

import * as dollarsValue from './index.js';
function intiualAdaptedVal(arr1, arr2, arrCid) { // arr1 => changeArr ; arr2 => dollarsValue
    let num;
    for (let i = 0; i < arr2.length; i++) {
        num = getNumber(arr2, arr2[i][1]) / arrCid[i][1];
        arr1[i].push(num.toFixed(2));
    }
    return arr1;
}
console.log(intiualAdaptedVal(changeArr, dollarsValue, cid))
But it doesn't work:

enter image description here

Thanks you

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

0

Since you are using the ES module, you have to add

"type": "module",

in package.json

about 4 years ago · Juan Pablo Isaza Report

0

On 'index.js':

module.exports = { dollarsValue }

and for recalling in another file:

const arrayIndex = require('./index.js')
let array = arrayIndex.dollarsValue
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!