79395557

Date: 2025-01-29 01:46:31
Score: 3
Natty:
Report link

One way to achieve this could be doing such as:

var data = new Map();
data.set('b', 2);
data.set('c', 3);
var prependData = new Map();
prependData.set('a', 1);
prependData.set('z', 26);
var fullData = new Map([...prependData, ...data]);

// Check content
Array.from(fullData.entries())

Or to be closer to your question:

var fields = new Map([
    ['product_type', {
        value : 'PRODUCT'
    }],
    ['supplier_product_type', {
        value : 'INTERNAL'
    }]
]);

fields = new Map([['new_key', {
        value : 'new value'
    }], ...fields])

// Check content
Array.from(fields.entries())

Please be aware there is a performance penalty for doing so this way.

Also, please check this thread: Simplest way to merge ES6 Maps/Sets?

Reasons:
  • Blacklisted phrase (1): please check this
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Camille Drapier