<body>
<html>
<h2>
Create an array to defeat me! Pennywise the Dancing Clown!</h2>
<img src="https://ih1.redbubble.net/image.67293317.2772/raf,750x1000,075,t,101010:01c5ca27c6.jpg" alt="We all float!" style="width:304px;height:228px;">
<body style="">
<h2></h2>
Index
<input type="textbox" id="index" value = ""/>
<br/> Value:
<input type="textbox" id="value" value="" />
<br/>
<input type="button" value="Create Array" onClick="fillArray();" />
<br/>
<input type="button" value="Insert into Array" onClick="insertIntoArray();" />
<br/>
<div id="output">
</div>
JavaScript
var array = [];
// This is a global array to hold an array
var d = ""; // This is a global string for display output
function fillArray() {
// to clear the display
clearDisplay();
// simple loop to 100
//k is the value I chose for one of the variables for index. i was the obvious choice but I chose to do something different.
for (var k = 0; k < 100; k++) {
array[k] = Math.floor(Math.random() * 100 + 1);
}
// this displays the array
displayArray();
}
function clearDisplay()
{
//d is used to hold display
d = "";
// The div element (output) is used to display the output
document.getElementById("output").innerHTML = "";
}
function displayArray()
{
// simple to add values to d
for (var k = 0; k < array.length - 1; k++) {
d += k + ' : ' + array[k] + "<br/>";
}
document.getElementById("output").innerHTML = d;
}
function insertIntoArray() {
clearDisplay();
// you have to get the value of index to insert data
var k = parseInt(document.getElementById("index").value);
// get actual value to insert at index i
var v =
// Display the array that was created from inserted values up to 100
displayArray();
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.