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

79
Views
How to add 2 String into array conditionally and print those value one down the other

i have an array that is empty initially later put some conditions and print those items

const myItems= []
-----other code goes here
myItems = someCondition : "A B" : "A"

if someCondition is true should look like one or the other down

   "A"

   "B"

else

  "A"
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

you could simply do this :

const myItems = [];
myItems.push((condition ? "A B" : "A").splite(" "));
about 4 years ago · Juan Pablo Isaza Report

0

Just push one of the expressions.

const items = [];

items.push(condition ? 'A B' : 'A');
about 4 years ago · Juan Pablo Isaza Report

0

You could do use this:

var myItems = [];
let someCondition = Math.random() > 0.5;
myItems = someCondition ? "A B" : "A";

myItems.split(' ').forEach(e => console.log(e));

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!