A
A
Alex102142021-06-20 15:29:54
JavaScript
Alex10214, 2021-06-20 15:29:54

What is the correct way to use indexOf()?

Greetings, I have conditionally three objects.

a = {value: 'ST'};
 b = {value: 'AP'};
 c = {value: 'STT'};

I iterate over the objects by the string "ST", BUT indexOf finds two objects (with the value "ST" and the value "STT", but of course I need it to find only with the value "ST", please help me write it correctly.

Here is my code:
const arr = [ this.a, this.b, this.c];

    const simple = 'ST';

    for (const el of arr) {
      if (el.value1.indexOf(simple) !== -1) {
        console.log(el);
      }
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2021-06-20
@Alex10214

Why do you need indexOf? What prevents to use the usual equality?
el.value1 === simple

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question