Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Incorrect value returns

I use this function:

function search (){
  v = [[2.0], [3.0], [4.0], [5.0]]
  if(v.indexOf(2.0) != -1){
    Logger.log ('if')
  }else{
    Logger.log('else')
  }
}

editing

My real need is in the values of words like this
I was answered about numbers so I did not change and only added

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

function search (){
  v = [["One"], ["two"], ["three"], ["four"]]
  if(v.indexOf("One") != -1){
    Logger.log ('if')
  }else{
    Logger.log('else')
  }
}

And instead of "if" returning to me, "else" returns to me.
I apologize for the broken English

>Solution :

You input array is a multi/two dimensional array. You are searching for 2.0 which is actually embedded inside another smaller array. Try changing the function to below.

function search() {
  v = [
    ["One"],
    ["two"],
    ["three"],
    ["four"]
  ]
  if (v.findIndex(e => e[0] === 'One') != -1) {
    console.log('if')
  } else {
    console.log('else')
  }
}

search();
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading