-
passing values from a for loop into another array
I am retrieving values from a XML file and storing them into an array called wordList using Actionscript 3.
Say these are the values of wordList bear, cat, dog, kite, chair
I need to then format the values and store them in an another array called words so that the array called words looks like this
words=[" bear", "cat", "dog", "kite", "chair"];
How can I wrap each value of the array in quotation marks and pass them to the array called words?
MY CODE AT THE MOMENT
Code:
function RetrieveWords(puzzleInput:XML):void {
var wordList:XMLList = puzzleInput.Word.puzWord;
for (var i:int = 0; i < wordList.length(); i++)
{
var wordElement:XML = wordList[i];
pWord.push(wordElement);
trace(pWord[i]);
}
trace("words");
pWord.toString();
trace(pWord);
}
trace(pWord[i]) lists the words like this bear cat dog kite chair
***trace(pWord) lists the values as
bear,cat,dog,kite,chair
I need to wrap each value in quotes and pass it to the array called words so that it looks like this
words=["bear", "cat", "dog", "kite", "chair"]
-
PHP Code:
var wordList:Array=new Array("bear", "cat", "dog", "kite", "chair");
var words:Array=new Array();
for (var i=0; i<wordList.length; i++) {
if (typeof(wordList[i])=="string") {
words.push(wordList[i]);
} else {
trace(typeof(wordList[i]));
}
}
trace(words);
Check this.....
arkitx
-
Originally Posted by arkitx
PHP Code:
var wordList:Array=new Array("bear", "cat", "dog", "kite", "chair"); var words:Array=new Array();
for (var i=0; i<wordList.length; i++) { if (typeof(wordList[i])=="string") { words.push(wordList[i]); } else { trace(typeof(wordList[i]));
} } trace(words);
Check this.....
arkitx
Thanks for the reply. The values can't be hard coded as they are been read from an xml file. I have an array called words that I could easily hard code the words into, however it needs to be dynamic.
-
Can I ask why the quotes need to be stored in the array? Try this in your code:
pWord.push('"'+wordElement+'"');
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|