Thursday 27 April 2017

nodejs - array search and append

I need a help from node experts... Version I must use is 0.10.x

I have an array like this:

[ 
    [ 'ABC', '5' ] ,
    [ 'BCD', '1' ]
] 

and I have new values to enter [ 'DDD', '3' ] and [ 'ABC', '4' ] and what I would like to achieve is to search if first column exists in array - if yes sum up second column, if not just add values to the array.

In result I would expect to have:

[ 
    [ 'ABC', '9' ] ,
    [ 'BCD', '1' ] ,
    [ 'DDD', '3' ]
] 

Please help

mfpass



via mfpass

No comments:

Post a Comment