adobe / adobe/adobe-client-data-layer

Clear Arrays by pushing an empty array

Open
#125 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
JavaScript
Stars
122
Forks
28
PR merge metrics
No merged PRs in 30d

Description

Let's start with this simple DataLayer object:
```
{
page: {
campaigns: ['campaign1', 'campaign2']
}
}
```
Then I push this:
```
adobeDataLayer.push({
page: {
campaigns: []
}
});
```

### Expected Behaviour
adobeDataLayer.getState() returning this:
```
{
page: {
campaigns: []
}
}
```

### Actual Behaviour
adobeDataLayer.getState() returning this:
```
{
page: {
campaigns: ['campaign1', 'campaign2']
}
}
```

### Workaround
You need to push `null` to delete it before setting it to an empty array as described above.
```
adobeDataLayer.push({
page: {
campaigns: null
}
});
```
The other way would be to first find out how many items there are in the array already and do a push like this:
```
adobeDataLayer.push({
page: {
campaigns: [null, null]
}
});
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.