0

I've tried the format like

['mobile-number', 'name', 'about'].includes(stages)

But that doesn't seem to work.

if (stages.includes('mobile-number') || stages.includes('name') || stages.includes('about')) {
    array.push('about-you')
}
DecPK
  • 24,537
  • 6
  • 26
  • 42
unicorn_surprise
  • 951
  • 2
  • 21
  • 40
  • Use [`every`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/every) or [`some`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/some)? – Sebastian Simon Dec 07 '21 at 05:39
  • what is the type of `stages` ? is it another array? or a normal string? – Ahmad Dec 07 '21 at 05:47

1 Answers1

3

Your looking for Array.prototype.some

stages.some(s => ['mobile-number', 'name', 'about'].includes(s))

This is the exact alternative of stages.includes('mobile-number') || stages.includes('name') || stages.includes('about')

Abdennour TOUMI
  • 87,526
  • 38
  • 249
  • 254
  • The caveat is stages type is unknown as OP missed it, hope its string, else you need to update the answer with the assumption that its a string type – Tushar Gupta Dec 07 '21 at 05:51
  • Though, we can guess that. Because if it's String, there is NO complexity , and it must be `[...].includes(stages)`.. however, the semantic of question should mean a relationship between 2 arrays, not array+string – Abdennour TOUMI Dec 07 '21 at 05:53
  • yeah unknowns and assumptions are the greatest enemies, totally agree what you said, but the facts are still unknown – Tushar Gupta Dec 07 '21 at 05:55