score:3
there's two issues here. firstly the braces around the second map()
call will be interpreted as a code block, yet it does not return any value so the resulting array will be empty. remove those braces.
secondly, item.column.path
needs to be item[column.path]
as you're using column.path
as the property accessor of item
.
here's a working example:
const movies = [{_id:"5b21ca3eeb7f6fbccd471815",title:"terminator",genre:{_id:"5b21ca3eeb7f6fbccd471818",name:"action"},numberinstock:6,dailyrentalrate:2.5,publishdate:"2018-01-03t19:04:28.809z",liked:!0},{_id:"5b21ca3eeb7f6fbccd471816",title:"die hard",genre:{_id:"5b21ca3eeb7f6fbccd471818",name:"action"},numberinstock:5,dailyrentalrate:2.5},{_id:"5b21ca3eeb7f6fbccd471817",title:"get out",genre:{_id:"5b21ca3eeb7f6fbccd471820",name:"thriller"},numberinstock:8,dailyrentalrate:3.5},{_id:"5b21ca3eeb7f6fbccd471819",title:"trip to italy",genre:{_id:"5b21ca3eeb7f6fbccd471814",name:"comedy"},numberinstock:7,dailyrentalrate:3.5},{_id:"5b21ca3eeb7f6fbccd47181a",title:"airplane",genre:{_id:"5b21ca3eeb7f6fbccd471814",name:"comedy"},numberinstock:7,dailyrentalrate:3.5}];
const columns = [{path:"title",label:"title"},{path:"genre",label:"genre"},{path:"numberinstock",label:"stock"},{path:"dailyrentalrate",label:"rate"}];
let output = movies.map(item => columns.map(column => item[column.path]));
console.log(output);
Source: stackoverflow.com
Related Query
- unable to destructuring two objects simultaneously
- Updating two objects of state array simultaneously in React
- Destructuring two objects
- React / Axios: Unable to set state on two objects at the same time
- check if two arrays contain identical objects - react componentDidUpdate
- TypeScript: Interface cannot simultaneously extends two types
- Unable to use two modals on same page using useDisclosure() in ChakraUI
- Merge two objects in javascript ignoring undefined values
- ReactJS: Unable to map through array of objects
- Unable to figure out how to highlight or select individual objects in InstancedMesh and display custom HTML tooltip using react three fiber
- How to merge two array of objects with reactjs?
- How can you merge two objects into same property in JavaScript?
- Determine if two objects have an identical structure with Jest
- Two divs scroll simultaneously until one reaches bottom
- How to pass objects and states between two components in React
- Combine two objects in react, no success so far
- Comparing two arrays and adding objects to the other one
- React useEffect() : Most efficient way to compare if two arrays of objects are equal
- ReactJS : Immutable.js : merge two Json objects
- Swapping two objects in array: ReactJS
- Merging two arrays into one that has the same amount of objects
- Unable to access element from array of JSON objects
- React Redux: Unable to Map array of Objects
- Creating an array in React with objects created from two lists
- Combining objects with object destructuring and the turnary operator
- React - componentDidUpdate() is unable to find DOM objects rendered by the render() method
- Return one or two objects with getDerivedStateFromProps?
- Need help to map two arrays with objects together bases on proprty
- Unable to run unique iterations for individual objects
- Remove equal objects from two arrays
More Query from same tag
- Failed to set State on onClick event to store id of clicked element by using useState
- When we use JSX <div></div>, or React.createElement("div", ...), is this virtual DOM (element)?
- Next.JS implement external ".js" with <script>
- Twitter App Authentication in Node environment, React
- How to make Material-UI CardActions always stick to the bottom of parent
- React Update a list with New Items But Ids might repeat
- How can i get a single data from local api using react and redux?
- Is it possible to separate presentation and logic for component in Redux/React?
- How to get access to this.props.location in child component?
- Styled component, breaks on google chrome
- React looping and creating new array with nested objects
- use an array which is defined in another file using react?
- Loading screen using Semantic UI React
- Redux Persist not persisting state with async reducers
- How to invoke onChange for radio button using react-bootstrap?
- What is the correct way to pass a token to axios from React?
- Functional Component to display input fields
- React-Redux mapStateToProps value is undefined after being set by reducer
- Best way to handle images and links from a rest api and displaying them in React
- React + Express.js server should always return the same index.html file, no matter what url route
- Create-react-app css modules with typescript: Cant resolve .module.css
- Why setState interrupt componentDidUpdate?
- webpack options has an unknown property 'hotOnly'. Invalid options object. Dev Server has been initialized using an options object
- React Component does not update when receiving an array of objects with reverse order. What can I do to make it updated?
- How do I write data to an array using checkbox?
- Cannot read property 'todos' of undefined ReactJs,Redux
- How to wait until a value is defined until passing it down as a prop in a component
- React, can you make an array of elements with Array(n).fill(0).map?
- How to add email validation to below code?
- State Management in NextJS