0

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.

1
  • 2
    Yes, code would be appreciated. Commented Mar 25, 2014 at 21:35

2 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.