I have an array that looks like: [x, y]. While y will always remain constant. I want x to be incremented by 100 every iteration.
This is what I did:
let arr = [
{
"name": "pies",
"data": [
[
"us",
149045
],
[
"es",
41746
],
[
"uk",
37640
],
[
"au",
16594
]
],
},
{
"name": "cakes",
"data": [
[
"us",
128845
],
[
"es",
35752
],
[
"uk",
32246
],
[
"au",
14333
]
],
}
];
let inc = 100;
arr.forEach(d=> {
d['m_arr'] = [inc, 125];
inc +100;
});
console.log(arr);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
As you can see, it is not incrementing the value. It is always just inserting [100, 125]. In the first object with the name, pies I want the m_arr: [100, 125] and the next object with the name, cakes to be [200, 125].
How do I do that?
inc +100=>inc += 100.mapinstead of.forEach?