user35533
user35533

Reputation: 1

Javascript Dynamic Array Calculator/Generator

Is there a way to create a dynamic array of integers on Javascript?

Let me explain a little further. I am designing a number generator that allows the user to input 9-13 numbers, select 3 "places" in that array, and input another number to fill those spots, so that the original number is altered in the output.

Example: The user enters 123-12-1234 The user selects the [0], [1], [2] The user inputs 5 Result: the output is 555-12-1234

Code is appreciated.

Upvotes: 0

Views: 277

Answers (2)

Sam
Sam

Reputation: 251

There's functions to the Javascript 'Array' object. On http://www.w3schools.com/jsref/jsref_obj_array.asp, you can find all functions and properties. Some examples:

var list = new Array(123,475,142,89);

Adding/deleting an element to/from the array:

list.push(286);
    // Added integer '286'
var num = list.pop();
    // Returns the last element and deletes it from the array
var index = list.indexOf(475);
    // Returns the position of element '475' in the array, if present

Go check out the link.

Upvotes: 0

Russ Cam
Russ Cam

Reputation: 125498

Something like the following should get you started

var arrayOfInts = [];

var input = ""; // accept user input in some way (text input in page?)

arrayOfInts.push(parseInt(input, 10));

// Now work with arrayOfInts

Upvotes: 1

Related Questions