Using ((unique array)) in the program - Forum

Forum Navigation
You need to log in to create posts and topics.

Using ((unique array)) in the program

Hello and good time, dear friends, how to put a variable received from the program into a JavaScript code and process it, and then get the result! The desired code is attached! thanks all

Uploaded files:
  • You need to login to have access to uploads.

@javadrajabihakami please try this instead:

CreateArray [numbers] 1,2,3,4,4,4,5,6,6,7,7,8
CreateEmptyArray [uniqueNumbers]
BeginJS
    function unique(arr) {
       var result = [];
       for (var i = 0; i < arr.length; i++) {
          if (result.indexOf(arr[i]) === -1) {
             result.push(arr[i]);
          }
       }
       return result;
    }
    $App.uniqueNumbers = (unique($App.numbers));
EndJS
jsAlert [uniqueNumbers]

Regards.

asmat and javadrajabihakami have reacted to this post.
asmatjavadrajabihakami

Hello and good time, thank you for your reply, dear teacher! The code works well! But my variable is a string type and I can't convert it into an array! Thank you for a guide in this regard! thanks again

Hi @javadrajabihakami

But my variable is a string type and I can't convert it into an array!

Sorry, I don't understand you. Please explain in detail. I have just edited your code.
Regards.

Hello again, I want to get my array from a string variable! But I do not succeed!

In the attached example, I defined a variable that has a number with the accepted array format!

And I want to use this in the sample code! But I will not succeed!

Uploaded files:
  • You need to login to have access to uploads.

Sorry, this is my problem! I can't set this variable for the array

Uploaded files:
  • You need to login to have access to uploads.

@javadrajabihakami Still not sure, but I think what you are looking for is StrParse command. It's used to convert a string with comma (or any other character) separated values into an Array.
Am I right?

javadrajabihakami has reacted to this post.
javadrajabihakami

Thank you for your reply dear friend! Yes, with this order, I managed to separate them! I am looking for a code that can remove duplicate elements from the array! I haven't succeeded yet! My array is of string type! And the previous code that you sent, I think it only worked with a good number!
Thank you for the help you have attached to this example. Thank

@javadrajabihakami But, it's just the same! Check this code:

SetVar [string] "one,one,two,two,two,three,four,four,four,four,five,six,seven,eight,nine,ten"
StrParse "[string]" "," [myArray]
CreateEmptyArray [uniqueStrings]
BeginJS
    function unique(arr) {
       var result = [];
       for (var i = 0; i < arr.length; i++) {
          if (result.indexOf(arr[i]) === -1) {
             result.push(arr[i]);
          }
       }
       return result;
    }
    $App.uniqueStrings = (unique($App.myArray));
EndJS
jsAlert [uniqueStrings]

 

javadrajabihakami has reacted to this post.
javadrajabihakami

Hello and good time, dear teacher, thank you for your kindness! This was exactly the code I wanted! Thank you very much! works well...

luishp has reacted to this post.
luishp