I need to send an HTTP API some JSON in the body like:
var body = {
'param1': 'param1 value',
'param2': 'param2 value',
'param3': 'param3 value',
'param4': 'param4 value',
'param5': 'param5 value',
'param6': 'param6 value'
};
But the source I have to build that from is
var datasource = {
'x4001': 'param1 value',
'jd5jj': 'param2 value',
'mmmmmoose': 'param3 value',
'simple': 'param4 value',
'crayonx3': 'param5 value',
'hubbabubba': 'param6 value'
};
There must be a quick jQuery replace/map function to create my 'body' variable from the datasource JSON - so that 'x4001' becomes 'param1', 'jd5jj' becomes 'param2', etc., etc. to get the body I crave?
in other answers I've seen, I see things like:
function renameProperty(obj, fromKey, toKey) {
obj[toKey] = obj[fromKey];
delete obj[fromKey];
}
addObjectResponse.forEach(obj => renameProperty(obj, 'SP02', 'O2'));
But my JavaScript / jQuery just doesn't understand anything with =>
in it - (which looks like LINQ statements from C#).
So - either I'm using the wrong jQuery, or I need a different solution?