0

In Chrome, Firefox & Safari I can merge 2 javascript objects using the spread operator:

const obj = { ...{'een' : 1}, ...{'twee': 2}}

but in MS Edge I get:

Expected identifier, string or number

...Why? !MS

dr jerry
  • 9,768
  • 24
  • 79
  • 122
  • 2
    Upgrade to Edge Chromium – mplungjan May 13 '20 at 12:59
  • it seems that it doesn't support it although that's odd, which version are you running? – EugenSunic May 13 '20 at 13:01
  • Maybe try lodash's merge() for browsers? https://github.com/lodash/lodash – Yakko Majuri May 13 '20 at 13:02
  • @EugenSunic & rest: I'm on Microsoft Edge 42.17134.1098.0. Company installation, so not in the position to update or do anything else. Copyrigh from 2018. Currently I feel most effective thing to do is tell my audience to avoid MS browsers. – dr jerry May 13 '20 at 13:06
  • The suggestion given by @Gbr22 can help to solve your issue. Object.assign is working fine with the MS Edge legacy browser. I suggest you can try to test it in the MS Edge legacy browser. – Deepak-MSFT May 14 '20 at 09:50

1 Answers1

1

You can use Object.assign()

const objects = [{'een' : 1},{'twee': 2}];
let obj = {};
objects.forEach(e=>Object.assign(obj,e));
console.log(obj);
kess
  • 1,204
  • 8
  • 19