score:1
You want the Object.keys()
function or the Object.values
const SUB_THEME = {
blue: 'Blue',
yellow: 'Yellow',
pink: 'Pink',
purple: 'Purple',
orange: 'Orange',
green: 'Green'
}
//this returns the keys
const theme_keys = Object.keys(SUB_THEME)
//this returns the values
const theme_values = Object.values(SUB_THEME)
Then you can map them like
theme_keys.map( key => {/*code here*/})
theme_values.map( key => {/*code here*/})
score:0
You can use as below :
Object.keys(SUB_THEME).map( (key) => {
console.log(SUB_THEME[key]
})
score:0
Object.keys(SUB_GROUPED).map(x => {
console.log(x)
})
score:0
Get object keys firstly with Object.keys(SUB_THEME).
score:2
Since you are trying to map an object you need to use Object.keys which returns an array of the objects keys that you can loop over.
Object.keys(SUB_THEME).map((key,index) => {
const subTheme = SUB_THEME[key]
return (
<label className={styles.label}>
<input
type="radio"
value={subTheme}
name={subTheme}
checked={subTheme === store.subTheme}
onChange={(e) => store.changeSubTheme(e.target.value)}
/>
{subTheme}
</label>
)
})
Source: stackoverflow.com
Related Query
- How can use my object like a array using with map function
- How can I use Map function for an Array with values and another array as a value in Javascript
- How to use if statement in array map function with next.js
- How to use map function with JSON object fetch though an API
- How to show the image links in an array of an object with map function in React?
- Rendering text boxes using map function for each object in this.state array. how can i handle text in the text area
- How Use images from javascript array in react using filter and map function
- React/Material-UI: How can I map multiple tables from a JSON object with more than one array of data?
- How can I set a specific position to array elements with the map function and a given index?
- Convert object to array with Lodash _.map and use map function in React
- How do i use props & map function to insert image urls for cards with logos using React?
- How can I use an array map of routes with BrowserRouter and Switch without them all loading at once?
- How can I use date type using map function in React?
- How can I use multiple refs for an array of elements with hooks?
- How to use jest.spyOn with React function component using Typescript
- How can I use e.preventDefault() in a function with more parameters?
- How can I use `setState` with objects nested in an array in React JS?
- How to use two map function with two fetching url
- How can I use an asynchronous javascript function like fetch inside a FormDataConsumer
- how can i use array in routing with react-router
- ReactJs: How to handle empty array with map function inside render method
- How to return only 1 item in an array in react using map function
- How can I conditionally map multiple arrays with if statements after fetching an array of objects? (React)
- how to compare id of html element inside of a map function with the id of an object outside of the map function
- How to use spread operator to delete an object from array of objects using spread operator using react?
- how do i update state in react for updating the value of an object inside an array using array.map function
- How to use map function with checkbox in ReactJS?
- How can I limit items in the cart with map function (ReactJS)
- How to map through an object with array of object
- How to use map function with react router?
More Query from same tag
- NodeJS + ExpressJS: Request header field not allowed by Access-Control-Allow-Headers in preflight response
- Actions (playing sound) based on Redux store changes
- Remove duplicate code in the reducer in react
- state data still keeps the previous state even after setState
- render component conditionally
- I cannot send base 64 url encoded data to my nodejs backend
- material-ui-next - Dynamically set palette color
- How to create a Javascript object from an array of known keys, but with the values initialized to null?
- React Node authentication
- When I first click the delete button, all the notes are disappeared but, when I refresh the page it works just fine
- Styled component in HOC
- React Custom Hook with Typescript Type error "Property 'x' does not exist on type 'interface | (({ target }: any) => void)'.ts(2339)"
- issue with set timeinterval in reactjs
- React JS Duplicate object within array
- ReactJS not render to div
- Create a pure function to merge objects
- Filter products by the name entered from the input
- React: Save multiple similar inputfields in one state
- How to push new FieldArray from outside render function?
- increment counter in the row
- React js, set class based on value
- Flux pattern for .net
- React state not updating as expected
- Counting multiple items with Redux
- Audio file doesn't play in reactjs
- ImmutebleJS in Redux - reducer get error "state.push is not a function"
- API response in useeffect with redux
- Having a react jsx component in state, Best practice
- First modal on each page not displaying data
- Next.js, why? Warning: Prop `style` did not match. Server: "object-fit: cover;" Client: "object-fit:cover"