educative.io

Educative

Please Explain the checking done

Can someone explain exactly the purpose of this checking?
if (index > -1) { // True if index greater than -1

He already got the index and the array was untouched before that… Why is solution checking if index is greater than 1? what is the purpose…?

From this chapter Solution: Musketeers - Complete JavaScript Course: Build a Real World App from Scratch

Hi @Mark_Medrano
if we try to extract an index of value other than what is present in musketeers like

var index = musketeers.indexOf("Java"); it will return -1.
So to verify the value of the index, we used this check.