I have an array containing ecommerce order info that I am pulling from the dataLayer into GTM. I have defined this order info as a variable that I want to pass on to a TikTok pixel for a Payment Complete event.

The problem I face is that the TikTok pixel expects the key name "id" to be called "content\_id" and the key name "name" to be called "content\_name". I understand that it is possible to perform a search and replace using a Custom Javascript variable in GTM, and then send the edited array on to the pixel. But I cannot figure out how to do the search and replace part using JavaScript. Here is what I am working with, this is what is in my variable:

```
[
  {
    id: "JBLANC015",
    name: "Blanc Diffuser, Maldivian Breeze",
    category: "Diffusers",
    price: "29.90",
    quantity: "3"
  },
  {
    id: "CH-AH-SHK-GREEN",
    name: "Hand Gesture Candle, Shaka  Green",
    category: "Candles",
    price: "39.90",
    quantity: "1"
  }
]

```

This is just an example, the array may contain more or less products, all instances of "id" and "name" need to be replaced with the correct ones that the pixel will recognize.

Here is an [extra-explanatory screencast video](https://videoshare.nextlevelbros.com/conversations/af586468-2f38-5968-827f-a4210f4f3e6c) in case that helps.

I have tried this:

```
function(){
   var str = {{my array variable}};
   return str.replace("id", "content_id");
}

```

But no success.

Edit. After understanding the difference between dealing with strings and arrays I got something like this which is working for changing one key at a time:

```
function(){
var products = 
[
  {
    name: "Hand Gesture Candle, Shaka  Green",
    id: "21834",
    price: "39.900000",
    brand: "Candlehand",
    category: "Candles"
  }
]
;
products.forEach(function(obj) {
  obj.content_name = obj.name;
  delete obj.name;
});
return products;
}

```

This does the job, but not when I plug in a variable that is pulling the array straight and live from the website.

```
function(){
var products = {{my array variable}};
products.forEach(function(obj) {
  obj.content_name = obj.name;
  delete obj.name;
});
return products;
}

```

When I use this version seen above with the variable the "name" key gets deleted and I do not get the changed "content\_name" key in the returned data. No doubt something simple that escapes me.

There is a similar question here [Google Tag Manager > dataLayer variable find and replace with javascript variable](https://stackoverflow.com/questions/39642299/google-tag-manager-datalayer-variable-find-and-replace-with-javascript-variable) but could not get the suggested answer to work for me or to extract a working solution from it.

Any help will with this would be super appreciated.