I have two data collection 1 which contains the header data or the column to be displayed.
Another is the actual data source.
Now what I have to do from that JSON data I have to select only that data which are in that header list.
Below is the sample of the data
Header Data Array: ["Execution_Plan_Note", "Budget", "Reporting_Period", "Budget_Note", "Spend_Plan_Note", "Spend_Plan"]
And Actual Data Source
So from the below collection, I want only data that are in the header data array in the new object how I can achieve this if any 1 has an idea let me know i have tried almost everything.
You can try with map
and reduce
like below.
const keysArray = ['a', 'b']; const list = [{a: 'a', b: 'b', c: 'c'}, {a: 'a1', b: 'b1', c: 'c1'}, {a: 'a2', b: 'b2', c: 'c2'}]; const result = list.map(item => keysArray.reduce((acc, key) => { acc[key] = item[key]; return acc; }, {})); console.log(result);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.