[javascript] How to convert an array of key-value tuples into an object