ledinos1
ledinos1

Reputation: 59

JS displaying strings in array

I have created an array

var array1 = new Array("jack", "kaziu", "wladek");
var display = Math.floor((Math.random() * array1.length));
console.log(display)

I cannot figure out how to display characters instead of numbers (array1's length). Appreciate for help.

Upvotes: 0

Views: 51

Answers (1)

jo_va
jo_va

Reputation: 13964

Index the array with your calculated index:

const array1 = new Array("jack", "kaziu", "wladek");
const display = array1[Math.floor(Math.random() * array1.length)];

console.log(display);

Upvotes: 2

Related Questions