score:1
Accepted answer
Use Array.map
:
const array = [
"first",
"second",
]
const res = array.map(e => ({
label: e,
value: e
}))
console.log(res)
score:0
Why not try this one?
const array = [
"first",
"second",
]
let arr_obj = []
for (let i in array) {
arr_obj.push({
label: array[i],
value: array[i],
})
}
console.log(arr_obj)
Source: stackoverflow.com
Related Query
- How to loop through an array an put create an array of objects using react and javascript?
- How to map through array of objects and create a new array of objects with a new added property using react and javascript?
- How to extract only values from array of objects and put it to an array using react and javascript?
- How can I create and loop through a custom array within a react functional component?
- How to recursively loop through array of objects and find the index of matching id using javascript and react?
- How do I create an array of objects in a React class component through a for loop to be mapped in a functional component?
- How to loop through properties of objects inside of an array within a React component?
- How to iterate through array of objects and execute a request using react?
- How to find the count of some object property in array of objects using react and javascript?
- Loop through array of objects and display them in react component
- Using javascript how can I loop through regex matches and split string into array of pieces divided by hyperlinks?
- how to loop through data and assign values to state array in react
- Javascript - How to loop through an array over and over again in React
- How to loop through an array of objects and get specific key values in React?
- Loop through array in React and create elements (not list items) from it
- loop through multiple objects inside the first array from JSON data displaying two arrays with objects in React using FUNCTION COMPONENT
- how can i loop through the array inside of an object. and render it in the react component
- How to save JS objects in array using react native AsyncStorage and display in a Flatlist
- How do I loop through child array and check if component exists React Testing Library
- How to loop through array and push it into a seperate array based on some conditions using react?
- How to loop through an array and display data within the object of that array, in react and javascript
- How to create nested array of objects using useState react hook
- How to add a type for array of objects using react and typescript?
- How to create dynamic array using checkbox and mapping in React JS?
- How do i loop through an array of objects in react
- How to map through and store an API response as an array of objects in state React JS
- How to fetch an array of objects and render it in the component as a normal text using React Hooks?
- Microsoft Graph Toolkit - How to loop through Get component result using React and default template
- How to set and access values of nested array objects in React state using useState hook?
- How to send array of objects data from child component to parent component and store in the parent object using react hooks?
More Query from same tag
- Props "undefined" within useEffect
- Not able to set initial values of formik form?
- Ignore click on transparent parts of images
- React npm start 127.0.0.1 instead of localhost on windows
- react hooks component not get new props value
- React: How to change status of toggle switch inside map?
- Navigating to a page on load in react JS
- How to create a setState wrapper that accepts arbitrary objects
- React onChange function does not fire when passing it down to component
- Favorites not refreshing upon post to database
- Graphql Apollo Client can't see Authorization header
- Radio button select issue, while using Map function
- React call API filter out undefined promises
- I want to insert different array values ​per object into an array inside the object
- Having trouble manually adding 'Other' option in React. What gives?
- How to use nested optgroup reactjs
- Single function for state change no multiple states whit similar name
- React - Testing external function in a functional component
- object didnt get passed to another method (React)
- Efficient way to init state storage of forms
- How to add new elements to table using ReactJS
- React FilePond (functional component) plugins not working even though I'm not getting errors?
- Draw a dashed path using Framer Motion in React
- Redux trigger action from the component
- save chart html to word file as image
- How to export all components in index.js?
- How to access array inside a json objectin react js
- Maintain usestate for different onclick
- react.js the above error occurred in the <div> component (there is no error above)
- What is the correct pattern in React JS to invoke a component method on specific props change?