Here is a JSON data that needs to be processed:
var oldArr =
[{
"careerLevel": "Associate",
"careerLevels": [
{
"201609": 21,
"201610": 22,
"careerID": "10000120"
},
{
"201609": 31,
"201610": 32,
"careerID": "10000130"
}]}];
Now, let's convert the above JSON to:
var newArr= [{
"201609": 52,
"201610": 54,
"careerLevel": "Associate",
"careerLevels": [
{
"201609": 21,
"201610": 22,
"careerID": "10000120"
},
{
"201609": 31,
"201610": 32,
"careerID": "10000130"
}]
}];
I am attempting to perform summation using the reduce() function:
var arr = [{x:1},{x:2},{x:4}];
arr.reduce(function (a, b) {
return {x: a.x + b.x};
});
console.log(arr); //Outputs the same initial array
var reduceArr = oldArr.reduce((sum, item) =>
const total = sum + item.201609; // this is giving me an error
);
Although I have some knowledge of the reduce function, I am still relatively new to this concept.