Reputation: 5939
I have a list off foods and drinks that I want to export from a file like this:
// example.js
var foods = ['', ''];
var drinks = ['', ''];
I would like to export those, so I can import them as:
import {foods, drinks} from './example.js'
console.log(foods); // ['', '']
My question is, how should I export them in the first example to get them in the second example
Usually I export one object from a file and that works, but multiple I am not sure
Upvotes: 10
Views: 11681
Reputation: 27192
You can export multiple objects like this in ES6 :
// example.js
var foods = ['', ''];
var drinks = ['', ''];
export {
foods,
drinks
}
Then, when importing you do it like this :
import { foods, drinks } from './example.js';
For more info, check this import and export.
Upvotes: 11
Reputation: 1261
// example.js
export const foods = [...
export const drinks = [...
Use the export
keyword, and by not including the default
keyword, your import code should work just as you submitted it.
Upvotes: 13