Index:
<input type="textbox" id="index" value = "2"/>
<br/> Value:
<input type ="textbox" id="value" value="10"/>
<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 = []; // Global array to hold array
var d = ""; // Global string for output
function fillArray()
{
// call function to clear the display
clearDispaly();
// A loop created to set array values from 1 to 100 in a random fashion.
for(var i = 0; i < 100; i++)
{
array[i] = Math.floor(Math.random() * 100 +1);
}
// Call the function to display the array.
displayArray(;)
}
// Below is the function used to clear the array.
function cleardisplay()
{
// Global string d is used to hold display.
d = "";
// the div element named output is used to display output.
document.getElementById("output").innerHTML = "";
}
// Below is the code used to display the array that was created in fillArray
function displayArray()
{
// Loop used to add values to string d
for (var i = 0; i < array.length - 1; i++)
{
d += i + ' :' + array[i]
+ "<br/>;
}
document.getElementById("output").innerHTML = d;
}
function insertIntoArray()
{
cleardisplay();
// Get value of index of value to insert
var i = parseint(document.getElementById("index").value);
d = "inserting " + v + " at " + i + "<br/>";
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.