+ 2
Hello everybody. That's my first code using JS. How can I pick a random value from an array with string values?
8 Respuestas
+ 3
This way
var s=["hello","spam","eggs"]
var a=s.length;
var b=Math.floor(Math.random()*a);
console.log(s[b]);
+ 6
Noël Julmiste Fils
let str="python";
console.log(str.slice(0,2));
//Output: py
+ 4
function random(arr){
return arr[Math.floor(Math.random()*arr.length)];
}
var myArr= ["a" , "b" , "c"];
console.log(random(myArr));
+ 2
Thanks
+ 2
Thank you Luis
+ 2
Thank you Mirielle,luis calderón,Abhay
+ 1
How can I slice like this in Js: name="python"
print(name[0:3]) will print "pyt". Please give me the way to use this in Js.