score:1
Accepted answer
you can reduce the object into a new object using object.keys()
and object.assign()
:
const obj = {
'harry-test-com': {
'quoteid234324': {
'day': 'tuesday',
'cost': '1000'
}
},
'sam-imaginarydomain-com': {
'quoteid13211': {
'day': 'wednesday',
'cost': '500'
},
'quoteid534534': {
'day': 'monday',
'cost': '300'
}
}
};
const result = object.keys(obj).reduce((days, user) => object.assign(days, obj[user]), {});
console.log(result);
a less supported option is to use object.values()
with object.assign
:
const obj = {
'harry-test-com': {
'quoteid234324': {
'day': 'tuesday',
'cost': '1000'
}
},
'sam-imaginarydomain-com': {
'quoteid13211': {
'day': 'wednesday',
'cost': '500'
},
'quoteid534534': {
'day': 'monday',
'cost': '300'
}
}
};
const result = object.assign({}, ...object.values(obj));
console.log(result);
Source: stackoverflow.com
Related Query
- Turn nested objects into single array of values
- How to turn an Array of objects into a nested object?
- Fastest way to sort array of objects on the basis of nested key values
- Comparison between objects values inside a single array
- Turn array of objects into list of options having label and value
- How to Calculate sum of values from objects insidte nested array
- Nested Array Of Objects into Downloadable CSV in react
- How to get values from one array of objects into another array of objects
- Turn 3 objects into multidimensional array
- Combine duplicate tokens inside huge JSON file into nested array of objects using React
- Turn an array of React context providers into a nested structure
- Rendering nested array object values into JSX element
- Combining all values in a Bacon stream into a single array
- Loop through an array of objects, find duplicate objects by id, add their values in a single object, react js
- How to Filter multi-select values in nested array of objects
- React: how can I add states that are objects into a single array and access it?
- How to push values correctly into an array of objects
- How to turn object values into new array in JavaScript
- How do I get values from a nested array pushed into a flat array?
- Push into array of objects with nested level using spread operator
- How to store all array values into a single React state?
- How to store values from a list into an array of objects in ReactJS
- Comparing two arrays of nested objects and return new array of objects if compared values are not the same in javascript
- Objects in array turn into undefined after using a particular reducer/action
- Check uniqueness with in nested object property values in array of objects
- How get to All values matching the query from mongodoDb at Once from multiple documents having nested array of objects
- How to update the value into a nested array of objects if value for specific key is same?
- Turning single objects into object array in ReactJS
- How to get common values of multiple nested array of objects
- How to disassemble an array of objects and nested arrays to Separated arrays with single data
More Query from same tag
- How to render parts of a render depending on props reactjs
- HTML canvas not drawing image
- abort http request on change reactjs
- React hooks, API-JSON HOLDER
- Handling redirection from an external server
- Unable to read data from Redux store in the React app
- react-bootstrap-table filter shows bad and headers are not aligned to data
- Stop propagation of all events
- How to display an error message for a specific time period within ReactJS?
- How do I apply 2 different stylesheets to one React component?
- React apps Localhost broken after installing bootstrap
- React hooks depends on another state can cause infinite loop. Why is that?
- Posting object from React.js to PHP using Axios
- React: Rendering a list in reverse order
- check if two arrays contain identical objects - react componentDidUpdate
- Change only one property of State şin React
- Trying my hand at hooks and state in a function in React.js
- Get the route path with special character and dynamic variable in react
- Validating that 2 fields are equal with Formik and Yup
- GatsbyJS: Replace part of the server side rendered html
- Cloudinary React not adding width and height attributes to img tag
- How to display and hide elements correctly in Reactjs
- Mobx store in react doesn't rerender components
- Eslint configure for react
- React -router doesn't add component to the dom
- Cannot use palette colors from MUI theme
- undefined error when trying to set state
- window.location.state.buttonEnabled always fails check for undefined with ReactJS
- Typescript React prop types with two possibilities
- React state not displaying appropriately