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

How can I compare two items that are of types Listitem and String?

Community Beginner ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

I got two kinds of items by different routes, with the result that their constructors are Listitem() and String(). They both look identical when printed out in the debug window, but they do not satisfy an == equality test. I've tried things like:

1. Convert one or the other to strings using toString()

2. Put the string into a list and then take it out - it's still a string! Here's the code I used

          //  x is the one whose constructor is Listitem

          //  y is the one whose constructor is string

          // Both look like "Snow" when you ask for them in the javascript console

          // First approach

                    x == y

          //Second approach

                    x.toString() == y

          //Third approach

                    x.toString() == y.toString()

          //Fourth approach

                   z = []

                    z.push(y)          //hoping to make the string into a list item

                    v = z[0]               //if you look after this, it's still a string!!!!

                    x == v

None of these work. How does one get across this artificial boundary to show them matching?

Thanks in advance...

TOPICS
Scripting

Views

266

Translate

Translate

Report

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

Guide , Jan 12, 2017 Jan 12, 2017

Hi Dick,

If you know that x is a ListItem and y a String, then x.text == y should be your comparison test, shouldn't it?

@+

Marc

Votes

Translate

Translate
Guide ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

Hi Dick,

If you know that x is a ListItem and y a String, then x.text == y should be your comparison test, shouldn't it?

@+

Marc

Votes

Translate

Translate

Report

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 ,
Jan 12, 2017 Jan 12, 2017

Copy link to clipboard

Copied

LATEST

that did work. Actually what was happening behind the scenes is that I was so frustrated about my big script not working for a demo last night that I changed the result return from the searching loop incorrectly, so the fact that the matching did work was hidden by the error in the return values from the function. Thanks for getting me to look with "new eyes."

Votes

Translate

Translate

Report

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