0

I'm importing some json from another files using es6 but when i try to gather them inside of another json object they added with variable name as array name.

element1.js

module.exports = {
   'element1': { foo: 'bar' }
}

element2.js

module.exports = {
   'element2': { foo: 'bar' }
}

when i run this code below;

import elementVar1 from './element1.js'
import elementVar2 from './element2.js'

const list = { elementVar1, elementVar2 }

list returns as below;

{
  elementVar1: {
     element1: {
        foo: 'bar'
     }
  },
  elementVar2: {
     element2: {
        foo: 'bar'
     }
  }
}

my aim is process these elements without any wrapper like this;

{
   element1: {
      foo: 'bar'
   },
   element2: {
      foo: 'bar'
   }
}

basicly i want to concat them

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143

1 Answers1

1

This should do...

import elementVar from './element.js'

const list = elementVar;

EDIT

Based on changed question... the solution will be as follows:

import elementVar1 from './element1.js'
import elementVar2 from './element2.js'

const list = Object.assign({}, elementVar1, elementVar2);
Santanu Biswas
  • 4,699
  • 2
  • 22
  • 21