正如我从你的问题中了解到的,你有下面的数组
[
{value: 'SimplePixel', name: 'Simple Pixel Call'},
{value: 'SearchTerms', name: 'Search Terms'},
{value: 'DataPartner', name: 'Data Partner'},
{value: 'Category', name: 'Category Rule'},
{value: 'GeoCountry', name: 'Geo Location Country'},
{value: 'GeoCity', name: 'Geo Location City'},
{value: 'ImpressionAdvertiser', name: 'Advertiser (Viewer)'},
{value: 'ImpressionCampaign', name: 'Campaign (Viewer)'},
{value: 'ClickAdvertiser', name: 'Advertiser (Clicker)'},
{value: 'ClickCampaign', name: 'Campaign (Clicker)'},
{value: 'ConversionAdvertiser', name: 'Advertiser (Buyer)'},
{value: 'ConversionCampaign', name: 'Campaign (Buyer)'}
];
在某些事件中,您希望移除第5和第6个元素,以便生成的数组
[
{value: 'SimplePixel', name: 'Simple Pixel Call'},
{value: 'SearchTerms', name: 'Search Terms'},
{value: 'DataPartner', name: 'Data Partner'},
{value: 'Category', name: 'Category Rule'},
{value: 'ImpressionAdvertiser', name: 'Advertiser (Viewer)'},
{value: 'ImpressionCampaign', name: 'Campaign (Viewer)'},
{value: 'ClickAdvertiser', name: 'Advertiser (Clicker)'},
{value: 'ClickCampaign', name: 'Campaign (Clicker)'},
{value: 'ConversionAdvertiser', name: 'Advertiser (Buyer)'},
{value: 'ConversionCampaign', name: 'Campaign (Buyer)'}
];
为此,我建议保留这样的两个数组
export const STATIC-PART = [
{value: 'SimplePixel', name: 'Simple Pixel Call'},
{value: 'SearchTerms', name: 'Search Terms'},
{value: 'DataPartner', name: 'Data Partner'},
{value: 'Category', name: 'Category Rule'},
{value: 'ImpressionAdvertiser', name: 'Advertiser (Viewer)'},
{value: 'ImpressionCampaign', name: 'Campaign (Viewer)'},
{value: 'ClickAdvertiser', name: 'Advertiser (Clicker)'},
{value: 'ClickCampaign', name: 'Campaign (Clicker)'},
{value: 'ConversionAdvertiser', name: 'Advertiser (Buyer)'},
{value: 'ConversionCampaign', name: 'Campaign (Buyer)'}
];
export const DYNAMIC-PART = [
{value: 'GeoCountry', name: 'Geo Location Country'},
{value: 'GeoCity', name: 'Geo Location City'}
]
现在在事件中,当您需要较大的数组时,添加动态部分并使用;当您需要较小的数组时,只需使用静态部分
要添加动态部件,请尝试此代码
const z = STATIC-PART.splice(4, 0, DYNAMIC-PART[0], DYNAMIC-PART[1]);
拼接的第一个参数表示在第四个位置发生变化
第二个参数指示要为我们删除多少项为0
其他表示要插入的项
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
阅读有关拼接的更多信息