خرید بک لینک

Vote count: 0

I've an array like:

a=[{'test':1,'test2':'2'},{'test':3,'test2':'4'}]

I'm trying to reduce this array to one object

Expected output

{1:2,3:4}

I've tried:

let newObj = a.reduce((pre,curr)=>Object.assign({},{curr.test:curr.test2}))//unexpected token at .
let newObj = a.reduce((pre,curr)=>Object.assign({},{curr['test']:curr['test2']}))//unexpected token at [

P.S: I have already achieved what I'm trying by not using arrow functions, I want to know why the above methods doesn't work

asked 3 mins ago

برچسب: نویسنده: استخدام کار تاريخ: پنجشنبه 6 خرداد 1395 ساعت: 12:43

صفحه بندی