javascript - Append an integer to a string name -


Hi H is trying to iterate for a loop with a long string of words organized in a string (wordlist),

Within effectjs:

  var wordlist3 = "hellwhentrysthisbreaks" var xc = 3; Var word_length = 4; Var word_ology = 4; For (i = 0; i & lt; words_in_round; i ++) {var num_words = ['wordlist' + xc]. Long / word_labee; Var random = math.flur (math.rendum) * ((num_words + 1) - 0)); N = Math.Round (Random / Term_Labby) * Word_Label; Random_word = (['wordlist' + xc]. Asbestring (n, (n + word_length)) random_words + = random_word; } The code above works if I define the wordlist globally, but when I have not defined it properly local num_words and throws a random word, then in this object There is no method substrings ..  

My problem is, since I change to local variables when I attach string names and calls. Length This gives me the length of the new name (wordlist3.length = 9) instead of the length of wordlist3 = 20; I can not even call this object based on the method ...

  ['wordlist' + Xc] .substring   

will never work (okay, Unless it happens before another variable, such as. foo ['wordlist' xc] .substring ). This is because, because in javascript, [anything] means an array of "anything", and arrays (described as Kendall) do not have a substrings method. Try

  random_word = (('wordlist' + xc) .substring (n, (n + word_length)) instead   

.

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -