Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Remove spaces from array

Community Beginner ,
Aug 07, 2015 Aug 07, 2015

I have an array of 13 items (all of which are letters EX e,e,e,e ...).  It is being read in from a database.  However, I want to loop through the array and clean out any spaces that it might have.  I am having trouble doing this.  Anyone done this before?

Here is what I have so far.

outputBox.autoSize = TextFieldAutoSize.LEFT;

displayArray(system.selectedAnswers.length);

function displayArray(n:int):void {

    for (var i:int = 0; i < n; i++)

    {

  system.selectedAnswers.replace(/^\s+|\s+$/g, "");

  outputBox.appendText(String(system.selectedAnswers) + ",");

    }

}

Thanks.

TOPICS
ActionScript
371
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 07, 2015 Aug 07, 2015

use a reverse for-loop:

function stripArrayF(a:Array):void{

for(var i:int=a.length-1;i>=0;i--){

a=a.split(' ').join('');

if(a.length==0){

a.splice(i,1);

}

}

}

Translate
Community Expert ,
Aug 07, 2015 Aug 07, 2015

use a reverse for-loop:

function stripArrayF(a:Array):void{

for(var i:int=a.length-1;i>=0;i--){

a=a.split(' ').join('');

if(a.length==0){

a.splice(i,1);

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 12, 2015 Aug 12, 2015

Thanks KGLAD

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 12, 2015 Aug 12, 2015
LATEST

you're welcome.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines