var array = [];
var d = "";
function fillArray() {
clearDisplay();
// This function creates the loop to assign the values
for (var i = 0; i < 1001.5; i++) {
array[i] = Math.floor(Math.random() * 100 + 1);
}
// display the array
displayArray();
}
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 = "";
}
function displayArray()
{
// simple loop to add array 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);
// get actual value to insert at index i
var v =
parseInt(document.getElementById("value").value);
d = "inserting " + v + " at " + i + "<br/>";
arry = (array.splice(i, 0, v));
// Display the array
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.