# get random element from array in javascript

Let's assume we have the following array:

```var arr = [16, 8 , 'bh' , 2 , 54 , 'foo' , 8852, , 'rr' , 2145 , 34, 89, 77];
```

We can get a random element by typing:

```var  random = items[Math.floor(Math.random() * arr.length)];
```

Article by Morning Train Technologies
{"ft_lang_label":"__label__en","ft_lang_prob":0.53934807,"math_prob":0.925012,"size":300,"snap":"2021-04-2021-17","text_gpt3_token_len":89,"char_repetition_ratio":0.12837838,"word_repetition_ratio":0.0,"special_character_ratio":0.37333333,"punctuation_ratio":0.2753623,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9593373,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-17T12:29:57Z\",\"WARC-Record-ID\":\"<urn:uuid:ea89dc71-c28e-4700-a41c-884a26597079>\",\"Content-Length\":\"38022\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:da52cee1-fcaa-4319-b815-432779b3aaef>\",\"WARC-Concurrent-To\":\"<urn:uuid:1acb6f8d-027d-489d-9595-8642db49e0cf>\",\"WARC-IP-Address\":\"104.21.67.179\",\"WARC-Target-URI\":\"https://codeontrack.com/get-random-element-from-array-in-javascript/\",\"WARC-Payload-Digest\":\"sha1:NGH7WYCNJFXKWK2OKML2G4ZJLVQAWG5K\",\"WARC-Block-Digest\":\"sha1:NQUUDOGOPIXRO4F3TI2YYHVI5SAHYLE6\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703512342.19_warc_CC-MAIN-20210117112618-20210117142618-00570.warc.gz\"}"}