Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

117
Vistas
Store array in JSON

I was trying store an array into JSON. For the JSON script, is it correct to write it just like this? {"bgArr" : ["bg1","bg2","bg3"]}

Might need some correction. I doing this to make the splice function to be fully work.

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 JsonObject, bgArr;

// JS array
var bgArr = [bg1, bg2, bg3];

// Convert (js array) to (json object)
JsonObject = JSON.parse(JSON.stringify(bgArr));

// type
console.log(typeof(JsonObject));

// JsonObject
console.log(JsonObject);


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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda