0

I am working with a object array in JavaScript and i want to output the code in a specific format i.e to remove the object array and created it like a array only and remove rest of the parameters.

 purchase_roas: [
            {
               action_type: "omni_purchase",
               value: "29.650019"
            }
         ],

The output I need is in this format: purchase_roas:29.650019

I tried using map function but the output is not the expected one. I used the code below:

for (var number in purchase_roas) {
  if (purchase_roas.hasOwnProperty(number)) {
    keys.push(number);
  }
}

The output i am getting is ["0"]

Jack Nezie
  • 21
  • 5
  • 1
    Can the `purchase_roas` array have more than one object in it? – Nick Parsons Jan 03 '23 at 06:53
  • the purchase_roas cannot have more than one object. The reason for this restriction is because if i get the purchase_roas:29; in this format it will be easier for me to output the data in google sheets. – Jack Nezie Jan 03 '23 at 06:59
  • Then simply `data.purchase_roas = data.purchase_roas[0].value` ..? – Teemu Jan 03 '23 at 07:00
  • Hey your method is working and i am getting the expected value too. Thanks for the help @Teemu – Jack Nezie Jan 03 '23 at 07:03
  • 2
    Please be clearer next time. If Teemu's comment is what you need, then it was extra trivial. – mplungjan Jan 03 '23 at 07:05
  • 1
    Hey mplungjan sorry the mistake but the output code i needed is to used inside a automation software where everything is predefiend like slice function map function there i cant write a single piece of code. Due to this reason i was confused and restricted to specific pre defined codes. – Jack Nezie Jan 03 '23 at 07:07

0 Answers0