score:0
Accepted answer
you cannot call map
on each order item as it is an object
. to iterate over them use object.entries
method.
try like below
{
orders?.map((order, idx) =>
object.entries(order).map(
([key, { description, title, price, cartquantity }]) => {
if (key !== "_id") {
return (
<tr>
<td>{key}</td>
<td>{title}</td>
<td>{price}</td>
<td>{cartquantity}</td>
<td>{description}</td>
<td>email</td>
<td>address</td>
</tr>
);
}
}
)
);
}
i also noticed your array has stored values with string keys (email
, _id
). to retrieve them you can do it like below.
{orders?.["email"]}
{orders?.["_id"]}
score:0
is data type array??
useeffect(() => {
fetch(`https://polar-savannah-40370.herokuapp.com/dashboard/orders`)
.then(res => res.json())
.then(data => setorders(data))
}, [user.email])
Source: stackoverflow.com
Related Query
- How can I destructure my array of multiple objects
- How can I asynchronously update multiple objects in the same array in React?
- How can I group an array of objects by field values multiple times?
- How can I map array with multiple objects and display on chart?
- How can I use multiple refs for an array of elements with hooks?
- How can I use `setState` with objects nested in an array in React JS?
- How to count multiple objects inside nested array sequentially in react js
- How can I use Promise.all on an array of objects and then reassign them to the relevant key in a new object?
- How can I delete Multiple array items
- How can I group objects alphabetacally within an array by a specific key?
- How can I send a file within an array of objects using formData.append()
- How can I filter through an array of objects based on a key in a nested array of objects?
- how can i setState inside of array of objects taking user input from form
- How can one property of an object from an array be true if that property of other objects is false?
- How can I conditionally map multiple arrays with if statements after fetching an array of objects? (React)
- How can I take only few property from my array objects in js
- how can i convert array of objects to one object
- How can I update the array of objects from a fetch response
- How can I make useEffect not return the initial value? I keep getting empty array when I'm trying to pass an array of objects into a component
- In React, how can I use "map" to transform an array of objects into a new array of objects?
- How can I filter from an Array that i created from another array objects in React?
- How do I specify an array with multiple objects in a TypeScript interface?
- How can I transform an array of objects into a new array of objects grouped by property?
- How can I shuffle an array of objects on page render and map over the shuffled array without console warning of "two children with the same key"?
- React: how can I add states that are objects into a single array and access it?
- How can I sort an array of objects by coordinate position and color?
- How can I compare two arrays of objects and add new key to an objects in the second array
- How can I extract a nested array of objects and put them in the core array?
- How can I make a conditional reduce call for an array of objects in React?
- How can I display an array of objects inside a object in React?
More Query from same tag
- Disqus email notifications open localhost instead of the real website
- Conditional rendering of HTML elements based on boolean value React
- Call Meteor method inside Apollo Mutation
- React Hooks - useState initializes empty array that becomes object?
- TypeError: environment.setup is not a function in React Testing
- React useState related issues, When passing an array to it
- How to map deep JSON data dynamically using React
- React.js add a class on socket.on
- "Cannot PUT /mytable" when running `UPDATE` SQL command from react-postgres "React App" localhost:MYPORT on PostgreSQL / node.js backend
- How to control audio/video DOM element in React
- @reduxjs/toolkit filter list
- Animate children when hover at parent with Framer-motion
- react - function inside useEffect
- Jest - Mock Nested Function
- Navbar component location doesn't update when route changed, with React Router
- Is there a way to append a json object into another json abject in react?
- Material UI - Change Font Size of TextField from Functional Component
- How to display EditText details below Labels in React js?
- reactjs application - can't get my hello world to show up
- Old values for React state while passing it to a function
- How do I access data returned from an axios get to display on a web page using react js?
- React-typescript and rendering array of components
- React bind issue and memory management
- delete song from redux state within reducer
- Logging within createApi redux-toolkit
- How is a React component called with parameters via a route?
- I try to parse my data with props between react components but I get undefined values
- ReactJS - Accessing Methods of Children (without using refs)
- Adding new element to page
- Note able to sort data in ascending/descending based on key of object in angular /typescript