El siguiente código hace lo que necesito pero me gustaría que se pueda adicionar más texto, pero crecería demasiado el archivo si tengo 1000 nombres.
function alea() {
variable = new Array();
variable[0] = 'David';
variable[1] = 'Lucas';
variable[2] = 'Nick';
variable[3] = 'Paul';
variable[4] = 'Marcos';
variable[5] = 'Luis';
aleatorio = Math.floor(Math.random() * 5);
return variable[aleatorio];
}
He visto que usan IndexOf() y Replace() para trabajar con cadenas… Me facilitaría cuando tenga que agregar cientos de nombres, pero no lo entiendo.
var notificacion = {
"Variable1": ["David", "John", "Paul", "Mark", "James", "Andrew", "Abel\r\n"],
"Contenido": "<p><strong>[variable1]<\/strong> Salio del sistema.<\/p>",
};
var z = Math.floor(Math.random() Variable1.length);
if (Contenido.indexOf([varible1]) + 1) {
var mensaje = Contenido.replace([varible1], Variable1[z])
} else {
var mensaje = Contenido.replace([variable1], Variable1[z])
}
return mensaje;