How to export test data (containing, arrays, json object, variables) to another js file?

Viewed 273

I want to export a test data but i keep getting stuck at some point. My test data is something like this. I have 2 json objects(mentioned only one in below code but both are similar),4 arrays, and 2 variables. data.js

exports.category={
    price : [
        {"film":
            {F: [a,b,c],
            I: [d,e,f],
            L: [g,h,i],}
    }
    ],
   arr1=[F,I,L],
   arr2=[10,20,50],
   arr3=[A,U,I],
   arr4=[2,5,10],
   minimumvalue=2,
   maximumvalue=5000,
}

I import the data in another js file with

import category from './data.js'; 

There were no explicit errors in editor but when i run the code, i get error as unexpected token

Unexpected token (61:7)

  59 |     }
  60 |     ],
> 61 |    arr1=[F,I,L],
     |        ^
  62 |    arr2=[10,20,50],
  63 |    arr3=[A,U,I],
  64 |    arr4=[2,5,10],
[0-0] FAILED in chrome -

I thought it is due to json object and changed my data into map array, even then i got errors w.r.t exporting. What am i doing wrong? How should i change it ? Thanks in advance

Update: After multiple attempts, i decided to keep all the arrays and variables in other file where i do my validations, now i am getting the below error.

[chrome 85.0.4183.83 Windows NT #0-0] json is not defined
[chrome 85.0.4183.83 Windows NT #0-0] ReferenceError: json is not defined

for validations, i will get the values first and then,with some conditions i already have, i will choose one value (like we do with excel by searching with row and column index)

1 Answers
  • You should format/indent your code better (tho that wont give you errors)
  • JSON objects use : to set a field, not =
  • The film property of price had "" around it and all the other properties did not

exports.category={
    price : [
        {
            film: {
                F: [a,b,c],
                I: [d,e,f],
                L: [g,h,i],
            }
        }
    ],
    
   arr1: [F,I,L],
   arr2: [10,20,50],
   arr3: [A,U,I],
   arr4: [2,5,10],
   minimumvalue: 2,
   maximumvalue: 5000,
}

Related