Author: codexwave.g1tech.in

Get Sum of Array Element

//Get Sum of Fruites from Array Element const fruites = [{‘apple’:4,’mango’:7,’banana’:10},{‘apple’:7,’mango’:2,’banana’:11},{‘apple’:1,’mango’:6,’banana’:14},];let cnt = [];fruites.forEach((v)=>{for(key in v){cnt[key]= (cnt[key]+v[key]) || v[key];}})console.log(‘v’,cnt)