0

const [data, setData] = useState({dataOne: "", dataTwo: ""});

How can i render both object values in One react table?

Here's Json Response

dataOne

[{
    "name": "adnan hassan",
    "count": 6960
}, {
    "name": "adnan",
    "count": 69666660
}]

dataTwo

[{
    "metrics": {
        "competition": "LOW",
        "avg_searches": "6600",
        "competition_index": "22"
    },
    "keyword_annotations": {
        "concepts": []
    },
    "text": "dubai homes"
}]

i want to show Count from dataOne & avg_searches, text from dataTwo in table. Map method Working one by one Like this data.dataOne.map() & data.dataTwo.map() But i want to render both values in one method like data.map()

2 Answers 2

1

You can merge the two arrays: using:

mergedArray = [...arr1, ...arr2]

dataOne = [{
    "name": "adnan hassan",
    "count": 6960
}, {
    "name": "adnan",
    "count": 69666660
}]

dataTwo = [{
    "metrics": {
        "competition": "LOW",
        "avg_searches": "6600",
        "competition_index": "22"
    },
    "keyword_annotations": {
        "concepts": []
    },
    "text": "dubai homes"
}]

let merged = [...dataOne, ...dataTwo]
console.log(merged)

// Then after you can map the data based on what you want
console.log('--mapped data starts here--')
merged.map((val) => {
  console.log(val)
})

Sign up to request clarification or add additional context in comments.

Comments

0

Thank you @Cypherjac for your direction. i solved this problam with https://lodash.com/docs/4.17.15#mergeWith

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.