Answer the question
In order to leave comments, you need to log in
How to convert object to URI?
What to get:
https://somesite.com/crm.contact.add.json?fields%5BNAME%5D=LOREM&fields%5BSECOND_NAME%5D=IPSUM&fields%5BLAST_NAME%5D=DOLOR
const OBJECT = {
fields: {
NAME: 'LOREM',
SECOND_NAME: 'IPSUM',
LAST_NAME: 'DOLOR',
}
};
Answer the question
In order to leave comments, you need to log in
https://developer.mozilla.org/ru/docs/Web/API/URLS...
https://developer.mozilla.org/ru/docs/Web/API/URL/URL
const OBJECT = {
fields: {
NAME: 'LOREM',
SECOND_NAME: 'IPSUM',
LAST_NAME: 'DOLOR',
}
};
const url = new URL('https://somesite.com/crm.contact.add.json');
for (const [name, value] of Object.entries(OBJECT.fields)) {
url.searchParams.append(`fields[${name}]`, value);
}
console.log(url.href);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question