I am having problem while using filter in react Hooks,how can i solve this issue?

Kaji Toon

I tried to use filter in react Hooks for filtering the state data fetched from the API but i get an empty array as output.How can i solve this issue?Following below is my code:

let FinalData = Data.filter((item) => item.district).map((item) => item.district);
let Testdata = District.filter((item) => item.title_ne === FinalData).map((item) => 
item.centroid.coordinates);
console.log("finaldata>>>", FinalData);
console.log("Districts>>>", District);
console.log("data>>>", Data);
console.log("Finally>>>", Testdata);

In every console.log i get the state value but in ' console.log("Finally>>>", Testdata);' i get output as empty array.How can i solve this issue?

Following are my output: enter image description here

adel

you need to find the title items with same titles in FinalData data you can do it like this :

let FinalData = Data.filter((item) => item.district).map((item) => item.district);
let Testdata = District.reduce((all,item) => FinalData.some(title=>item.title_ne===title)?[...all,item.centroid.coordinates]:all,[]);
console.log("finaldata>>>", FinalData);
console.log("Districts>>>", District);
console.log("data>>>", Data);
console.log("Finally>>>", Testdata);

use array reduce method instead of filter and map chain

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How can I solve error I am having while Inserting Tweet data into Apache Cassandra db?

How can I solve this problem in building apk using react native?

I'm having an error using modalroute can you solve the problem?

Is this a React prevState issue and how can I solve it?

How can I solve this using _.filter?

I am having a problem using rsync

how can i solve this issue?

I am having a bit of a strange error on mysql pdo. How can I solve it?

I am having an issue with my while loop, not too sure why

I am having a problem with reading a variable, comparing it and then printing the output while using loops

I am having a problem while packaging my electron app using the electron-builder?

i am having a problem in page navigation while using drawer and bottom navigation

I am getting a problem while using checkboxes

How can I solve "HTMLMediaElement already connected previously to a different MediaElementSourceNode" problem using React functional component

How can i solve uniqe key prop problem in React native

How can I solve this Fetch problem in React.js?

I am having issue with mapping the data in react native

How can I fix this problem that I am having with screen.blit in pygame in python?

I am having use with React router v6 while using Elements of stripe

I am having this issue in .format() , Can anyone elaborate this to me?

how can i solve the problem problem with this regex?

How am I using React hooks wrong here?

I am having an error while updating my states in react

how can I solve the prefix hierarchy problem using js

How can I solve the problem using super keyword in Java

How can i solve the problem with creating a class in java using Eclipse

Having an issue in Menu Tabs. And I am using carbonKit Framework

I am having this issue in my project using mongodb with node js

I have an issue in uploading file in laravel, how can I solve this problem?

TOP Ranking

HotTag

Archive