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")
})
Source: stackoverflow.com
Related Query
- How to parse the response of fetch as JSON
- How can i parse simple json response in fetch call
- How to parse json response using fetch API
- How to fetch the new data in response to React Router change with Redux?
- How to fetch data in getInitialProps with redux-saga.Then get the response from redux store while in the getInitialProps method?
- How to manipulate fetch response for single object JSON in react-native
- How to check the response from global fetch in JEST test case
- In React, how can a parent component set state from the response an async fetch function performed in a child component?
- How can I update the array of objects from a fetch response
- ReactJS : RestAPI JSON response : How to Parse
- How do I store the JSON response such that I can use it in other functions (React & JS)?
- How to fetch json data from a url that requires an api key to access the data in reactjs?
- How do I capture the response JSON from a 400 bad request with fetch?
- How to display the text with "anchor tag", coming from json response in react?
- How to save axios GET response data as json or as same as the arrived response
- How to parse a boolean from a JSON response in React
- How to parse JSON (key ,value) String on the UI side in javascript
- How can i fetch the categories in JSON url in ReactJs
- how can I use the JSON token Response returned by an endpoint to another .js file in React
- How can I parse the response of axios to an attribute in a React component
- How to save the response info in the Redux state after fetch into useEffect hook?
- How to get the response JSON from API call
- how to fetch the data from the response like array format using reactjs
- How to handle large sets of data response from an api fetch when no size/limit/count parameters are present for the api?
- How to pass the key used from JSON response objects in a map as a parameter for onclick() function in React?
- How do I fetch the response from an apiCall to display in my component?
- How to parse a HTML template from Json and populate the data
- In my rest webservice request for react using axios, the response json contains html div element. how can I get the value of this element?
- how to Display the response data after fetch in reactjs
- How to fetch the uploaded file path as response from rest-api call
More Query from same tag
- How to comment JSX code out in .js files in VSCode?
- PropTypes error when using Styled Components
- react-select don't show keyboard on mobile devices and prevent zoom
- How can I pass a prop to my home route after redirecting?
- React button not show results after first click, how do I fix it?
- need something like event.target.focus() in React
- Unit test doesn't update value on styled input
- How to run setSubmitting() outside the submit handler?
- React action always dispatch before resolve all promises
- ReactJS apolloClient Could not find "client" in the context or passed in as an option
- Uncaught TypeError: Cannot read property 'target'
- How to pass base64 string to a fetch API body payload?
- How to create a typescript decorator with react
- Remove comma if its the last item in the object
- React.js Component Child - Global interaction
- Efficient way to pass all valid props to child?
- Antd Fixed Header In Layout
- How to abort submit of <button> tag without "type" attribute?
- React-Router : Unable to redirect from / to /home
- Creating translation path in Gatsby
- React JS: Calling two functions in an onClick event does not run functions
- How do I render components with different layouts/elements using react-router-dom v6
- Make react components less verbose
- How to test that <Navigate /> will navigate app to correct component
- ReactJS: Collapsible sidebar overlaying on another component
- Material UI popover not working with react class component
- can't get response status code with JavaScript fetch
- Twitter App Authentication in Node environment, React
- Link cannot appear as a descendant of a link
- Property 'store' does not exist on type 'IntrinsicAttributes'