When I am using yargs module to simplify params handling
Yargs always reruns params as an object, here is an example, if I run this command node index.js default --optipn1=true --option2=false --custom
Yargs return this array:
{
_: [ 'default' ],
optipn1: 'true',
option2: 'false',
custom: true,
'$0': 'index.js'
}
What I want is the same array of params excluding _ and $0,
{
optipn1: 'true',
option2: 'false',
custom: true,
}
is there anyway to do that that?
Is there any built-in functionality to achieve that?
const obj = {
_: [ 'default' ],
optipn1: 'true',
option2: 'false',
custom: true,
'$0': 'index.js'
};
let newObj = {};
for(let [key, value] of Object.entries(obj)) {
if(key != '_' && key != '$0') {
newObj = {...newObj, [`${key}`]: value}
}
}
console.log(newObj)
Here we go ;) I hope be useful for you
let obj = {
_: ['default'],
optipn1: 'true',
option2: 'false',
custom: true,
'$0': 'index.js'
};
let {_, $0, ...targetObj} = obj;
console.log(targetObj);