Problem with Two array adding in a single array

Dear Developers, I am trying to develop chart using vue-google-chart . I have 2 array as like as below

amounts= [ [ ob : Observer] 0: “7800” 1: “2500” 2: “3000” 3: “5244” 4: “1700” 5: “13300”]

month=[“July”, “August”, “September”, “October”, “November”, “December”]

how can I put this 2 array at data chartData:[“Month”,“Amount”], ?? I used map key value but only months name successfully intregrated and amount values says undefined. I tried a lot of ways but nothing working . Thank you

my data should be like
[“Month”,“Amount”] [“July”,7800][“Augurs”,2500][“September”,3000]
this way.

Can you show us what code you have tried so far?

what’s the nature or the type of the amounts object.

1 Like browsers, is to include either Lo-Dash or Underscore in your page.
Then you can use either _.size(object) or _.keys(object).length

map function.,k)=>[v, value[k]])

it is coming from laravel .

So I’m curious - with amounts structured like that, what makes you think it’s an array? @OJL is right with his question, it’s not quite an array, and its not quite an object. It wants to be, but it is a very broken hybrid that should not actually work.

If it’s an array, it wouldn’t have each member defined like 0:"7800", as that is the definition for object properties. If it’s an object, then it wouldn’t be enclosed in angle brackets.

Without knowing exactly what you’re dealing with, we can’t really tell you how to get where you’re trying to go.

That said, assuming amounts is an object and months is an array, it’s pretty trivial. Using months.reduce will let you build a different object entirely. Here’s the idea:

const finalArray = months.reduce( function(accumulator, month, index){
   * Here, you want to set the new value in your accumulator to a sub-array, containing month
   *   and the member of the amounts object with the property name that matches this index:
  accumulator[index] = [/* in here, set the values. Not giving away all the answers... */];
  return accumulator;
}, []).unshift(["Month", "Amount"]); // this last bit will prepend the column names you want.

You could actually do much the same with map(), as I think about it, but value[k] is not doing much, if the amounts array is named amounts and not value

const finalArray = (mo, index) => [mo, amounts[index] ] ).unshift(["Month", "Amount"]);

let finalArray = (mo, index) => [mo, this.totalmoney[index] ] ).unshift([“Month”, “Amount”]);
return 7 .

Without seeing code in some sort of context, we’re stabbing in the dark. We don’t know, at this point, the nature of your variables or objects. The variables we were given initially are not the variables you’re referencing now.

If you can, even something like console.log(JSON.stringify(this.totalmoney) ) and copy/paste the result of that will give us a better handle on that thing, whether it’s amount or this.totalmoney. We don’t know what we’re getting in, so you can’t know what you’re getting out.

full code available here.