score:1
Accepted answer
if you really mean an object {strawberry: true, watermelon: true, pear: true}
(an associative array), not an array,
const options = [
{ label: "strawberry 🍓", value: "strawberry"},
{ label: "watermelon 🍉", value: "watermelon" },
{ label: "pear 🍐", value: "pear" },
];
const optionsobject = {};
options.foreach(({value}) => optionsobject[value] = true);
(you can also do this with .reduce
if you really want to:)
const optionsobject = options.reduce((obj, {value}) => {
obj[value] = true;
return obj;
}, {});
Source: stackoverflow.com
Related Query
- get key values pair from an array of objects and place in new array
- Get the component from array of objects and add new properties to it - React
- Consolidate array of objects with similar key values and create new array with less objects
- How to loop through an array of objects and get specific key values in React?
- Adding key value pair (value from an array) to specific objects in an array
- How can I use Promise.all on an array of objects and then reassign them to the relevant key in a new object?
- get all values from array of objects in react typescript
- Array of objects and i want to return true if any key value pair in the object is duplicate
- Javascript 2 arrays of objects , get a value from one array of objects and assign it to the other array of objects
- get lat and lng from array of objects on React
- Creating An Array of Objects From An Object Without Specific Key Values
- Sum total and make an array which count by same values from array of objects
- TypeScript React: Use an array of strings as an index and get values from state
- How to get values from one array of objects into another array of objects
- How to get value based on key from an array of objects javascript
- Find Numeric Values among string from Array of Objects and do calculation
- How to consecutively add values from one array to another and store the value in a new array in javascript?
- Filtering an object based on key, then constructing new array of objects based on the keys and values
- How can I compare two arrays of objects and add new key to an objects in the second array
- How do I iterate over an array of objects match a common element from another array and return the key value for "name"
- React replace certain key values from array of objects with asterisk in datatable row after fetching
- how make a new array of objects with different key names from another array of objects in JavaScript?
- How to add a string to Key of an array and get values
- How to extract only values from array of objects and put it to an array using react and javascript?
- iterate over array of objects and fetch only specific key to form a new array of object in react js
- Comparing two arrays of nested objects and return new array of objects if compared values are not the same in javascript
- How do I take an array of objects from state and push a specific value of the objects into a new array
- trying to get id's from array of objects and push those id's into array
- How can i get values from multiple input boxes on form submit and store the values as an object in an state array for React?
- react js filter through an array of objects and compare values within to get the closest value to a variable
More Query from same tag
- I have one this.state and i need pass in my componentDidMount with setState, how use bind(this) in setState?
- ReactJS: Passing String Literals into Global Constants
- ReactJS app doesn't work on mobile
- ScrollMagic with React
- Changes to React Router V4
- React JS Duplicate object within array
- Passing state to a child component of another child component
- React useEffect not triggered
- iPhone will only focus on one html input text of two on screen?
- Material ui dark mode reset when page refreshing?
- Install all unmet dependencies in yarn
- Material-ui v5 - where is DataGrid component? ( How to install DataGrid component in material-ui v5 In react?)
- Variables in graphQL queries
- Local storage using redux toolkit
- How to Write a jest test by mocking Axios, using the action provided?
- How to replace the value of an array of objects in React
- Dynamically import React component from external URL and use parent React environment
- Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead.(NEXT JS)
- Const value can be change
- React useState with Object with multiple boolean fields
- Spine and Reactjs issues error @esotericsoftware/spine-player' does not contain a default export (imported as 'spine')
- React - how to prevent re-render for child component
- Way to check if first iteration in map
- changing state derived from props before render
- Snap.svg in React - how to access the svg in a lifecycle method?
- Webpack + React + TypeScript: Module not found ... in ... node_modules/react/
- How do I display data from api using react and redux
- Moment returns wrong date for Unix timestamp
- React erroring because of different, mystery object
- How can I remove an array from my redux store?