Add to variable index ++ (var[i++]="first from array";) with javascript?
-
example: for (i in myArray){ mynew[n++]=myArray; } How to increment the index automaticaly in a loop. If I do myarray=new Array(); and latter myarray="first"; next time myarray="content"; will not result an array.
-
Answer:
Do not use a for in loop to iterate over the elements of an array. Use: for (var i = 0; i < myArray.length; i++) { myArray[i] = //Whatever you're trying to do. } Use the array literal notation instead of new. Example: var myArray = []; Instead of: var myArray = new Array(); If you assign myArray as an array type, then reassign it as a string, of course the result will be a string instead of an array. If you want to assign a string to an array element then use an index. Example: myArray[0] = "first"; //Assigns the string "first" to the element at index 0 of the array. - Dominic
Hooks at Yahoo! Answers Visit the source
Related Q & A:
- how can i remove an array from an array?Best solution by Stack Overflow
- How to add two variable in bash?Best solution by Stack Overflow
- How to dynamically create object properties from an array in Javascript?Best solution by nfriedly.com
- How to add music to the videos I make?Best solution by Yahoo! Answers
- How can I construct the array problem?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.