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

199
Views
How to write JSON into splice

I currently trying to splice an array one by one until empty. I wonder if I add JSON into it, will it work? Or is there any other way to splice an array one by one per attempt. Below is my script.

var promoCode = '';
var bg1 = 'https://cdn.pixabay.com/photo/2020/06/01/22/23/eye-5248678__340.jpg';
var bg2 = 'http://farm5.static.flickr.com/4017/4717107886_dcc1270a65_b.jpg';
var bg3 = 'http://images6.fanpop.com/image/photos/41500000/adorable-puppies-cute-puppies-41538743-590-393.jpg';


var bgArr = [bg1, bg2, bg3];
for(var i = bgArr.length-1;i>=0;i--){
  selectBG = bgArr.splice(Math.floor(Math.random()*bgArr.length), 1)[0];
  console.log(selectBG);
}



if (selectBG === bg1) {
  promoCode = 'SCRATCH400';
  
} else if (selectBG === bg2) {
  promoCode = 'SCRATCH500';
  
} else if (selectBG === bg3) {
  promoCode = 'SCRATCH600';
 
} else if (bgArr.length === 0) {
  alert("No more voucher, back to main website");
  window.location = 'https://www.google.com/';
}

about 4 years ago · Juan Pablo Isaza
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!