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

145
Views
Conditional array as a parameter inside array

I have this code:

const obj = new plugin.process({
  extensions: [...bindings, a, b]
});

Is there anyway to make the bindings optional based on another parm?

Say I have a boolean flag

 const obj = new plugin.process({
      extensions: [...bindings && myFlag, a, b]
    });

Any ideas?

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

0

You could simply construct the array before passing it into process.

First create your default array, this could be:

const extensions = [a, b]

Then add an extra condition in case your boolean is true:

if(myFlag) {
  extensions.push(...bindings)
}

Combining this together:

const extensions = [a, b]

if(myFlag) {
  extensions.push(...bindings)
}

const obj = new plugin.process({
  extensions
});

If bindings need to be added before a and b, we can write logic like this:

const extensions = []

if(myFlag) {
  extensions.push(...bindings)
}

extensions.push(a, b)

const obj = new plugin.process({
  extensions
});
about 4 years ago · Juan Pablo Isaza Report

0

Use this

const obj = new plugin.process({
  extensions: [
    ...bindings,
    ...(myFlag ? [a, b] : [])
  ]
});
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!