-3

Situation: I have an array called "array1" with some strings in it.

For example, when I type array1.length , then the program gives me the amount of strings in the array back. What do I have to do to get "6" back (The amount of letters in the array name "array1")

Christian
  • 9
  • 4
  • 7
    The name of a variable is not something that you can directly access in JavaScript. What is the problem you're trying to solve? – Pointy Mar 14 '16 at 20:02
  • sometimes you can http://stackoverflow.com/a/1009988/5742681 – KWeiss Mar 14 '16 at 20:09
  • @Pointy , in one situation my program should use the array which has one simple number behind the name (like array1). in the other situation it should use the arrays which have more numbers (like array1.2). I want to use .length to tell the program if it has a type 1 or type 2 array. – Christian Mar 14 '16 at 20:11
  • 2
    The idiomatic way to do that in JavaScript would probably be to keep the array in an object, accompanied by one or more other object properties to describe the array type. Basing behavior on variable names is quite unconventional in most common programming languages. – Pointy Mar 14 '16 at 20:13
  • I am new to coding, and this was the first idea that came to my mind. I have scenarios in my arrays and my program should use either type 1 or type 2 arrays , so it can continue with the story for my text adventure. (Because type 2 is the alternative story and type 1 the main story. – Christian Mar 14 '16 at 20:16

1 Answers1

0

maybe you could youst wrap the arrays with numbers in one array and the other ones in another array and just use the wrapper array you need.

without seeing your code this is the best solution i can give you

kpbl
  • 24
  • 2