I need to fetch the variable which is inside a function in class component. This is my function I want to fetch the "newArray" variable in class component.
handleChanges(event) {
this.setState({value: event.target.value});
console.log("value",event.target.value);
let values=['OurStory','HowItWorks','Blog','Login','BeaParopakari'];
console.log("values",values);
let url =
"http://localhost:49590/api/Authenticate/Translate?values=xxxxxxxxxxxxxxx";
let user = JSON.parse(localStorage.getItem("user"));
const accessToken = user;
console.log(accessToken);
fetch(url, {
method: "GET",
headers: {
"Content-type": "application/json",
Accept: "application/json",
Authorization: "Bearer " + accessToken,
"Access-Control-Allow-Headers": "Access-Control-Request-Headers "
}
})
.then((response) => response.json())
.then((data) => {
this.setState({
Details: data
});
console.log("Filter", data);
const longArray = data;
const size = 1;
const newArray = new Array(Math.ceil(longArray.length / size)).fill("")
.map(function() { return this.splice(0, size) }, longArray.slice());
console.log(this.state.newArray);
const trans = "Vijayaasri";
});
I tried it in state but it didn't work.
{this.state.newArray.map(s=>s.result)}
I use map function to fetch.
This newArray value I need to print in page. Please share your knowledge. Thank You in Advance.