score:0

Accepted answer

if the response is json, you have to parse it. you should use response.json() method instead of response.text():

fetch("http://localhost:8080/getnames")
  .then(response => response.json())
  .then(data => {
  alert("data: "+data);
  alert("index: "+data.indexof(value));
  data.indexof(value)===-1?callback():callback("duplicatename")
})

score:1

instead of response.text(), you need to write response.json() to test for the exact match, since reponse.text() will give you data as string while, response.json() will return the data to be an array

fetch("http://localhost:8080/getnames")
  .then(response => response.json())
  .then(data => {
  alert("data: "+data);
  alert("index: "+data.indexof(value));
  data.indexof(value)===-1?callback():callback("duplicatename")
})

Related Query

More Query from same tag