js get arguments of function code example
Example 1: javascript get parameter
let params = {};
window.location.search.slice(1).split('&').forEach(elm => {
if (elm === '') return;
let spl = elm.split('=');
const d = decodeURIComponent;
params[d(spl[0])] = (spl.length >= 2 ? d(spl[1]) : true);
});
params['foo']
params['best food']
Example 2: js unspecified parameters
function my_log(...args) {
console.log(args);
console.log(...args);
}
Example 3: how to access any argument in javascript
function example() {
console.log(arguments);
console.log(arguments[0]);
}
example('hi', 'hello');