Remove specific string between commas (with JS)

advanced-prototyping

#1

Hello, dear Axure Pros.
Does anybody know how I can сut with JS a specific string from an array?
e.g.:
Array:
Apple,Orange,Banana,Peach

cutting first: Orange,Banana,Peach
cutting second: Apple,Banana,Peach
cutting third: Apple,Orange,Peach
cutting fourth: Apple,Orange,Banana

I managed to cut the second and third, but can’t find a solution for the first and fourth with the same function.
The file with the example is here:
Cutting-a-string.rp (48.4 KB)

Thank you in advance!


#2

Hi!

I assume by JS you mean Axure’s built-in javascripty functions.

The only way I can think to do this is to create a loop that grabs the first item from the array and adds it to a tempArray if it’s not the undesired item. Since Axure doesn’t have loops, you’ll have to do it recursively. You’ll use the OnMove interaction of a hotspot or whatever to trigger the “function.” loopVar starts out at 0 and tempArray starts out blank. origArray holds the array.

Pseudocode:

OnMove
  if origArray still has a comma
    grab the first item, including the comma
    remove the same from origArray
    increment loopVar
  Else if origArray is not null
    It's the last item, so grab the whole of origArray
    set origArray to null
    increment loopVar
  If loopVar isn't the undesired index
    add the grabbed value from either condition above to tempArray
  If origArray isn't null
    we're not done, so move this (to trigger OnMove again - the recursive call)
  else
    we're done, so set origArray to tempArray 
    set loopVar to 0
    clear tempArray
    get rid of the trailing comma on origArray if it exists.

Here’s an example, with comments. The hotspot in _system has the code.
removeItemFromArray.rp (59.4 KB)


#3

@josephxbrick Awesome! Thank you so much!


closed #4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.