const href = 'https://example.com/?user=John&some_key=1&id=3';
const url = new URL(href);
const availableKeys = ['user', 'id'];
for (const key of [...url.searchParams.keys()]) {
if (!availableKeys.includes(key)) {
url.searchParams.delete(key);
}
}
console.log(url.toString()); // 'https://example.com/?user=John&id=3'
utm_delete
, тогда так:params.delete('utm_delete');
utm
: тогда из примера код. Можете и в enum
запихать:const utm = [utmType.UtmSource, utmType.UtmMedium];
for (const key of utm) {
params.delete(key);
}
// или
params.delete(utmType.UtmSource);
id
не очень хорошее. <?php
header('Content-Type: application/json');
print(json_encode($_POST));
interface IAction {
type: string
post: any
}
const test1 = (action: IAction): void => {
console.log(action.post);
};
const test2 = ({ type, post }: IAction): void => {
console.log(post);
}
type TAction = {
type: string;
post: any;
}
const test3 = (action: TAction): void => {
console.log(action.post);
};
const test4 = ({ type, post}: TAction): void => {
console.log(post);
};