Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
How to get all params exept '.$0' and '._' using yargs

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?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

let obj = {
  _: ['default'],
  optipn1: 'true',
  option2: 'false',
  custom: true,
  '$0': 'index.js'
};
let {_, $0, ...targetObj} = obj;
console.log(targetObj);
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!