I have created two dropdowns and I am getting the back-end data. Here, I wat to display the list of websites and stores as dropdown.
JavaScript
x
11
11
1
[
2
{
3
store: [],
4
website: "storeuiteam",
5
},
6
{
7
store: ["MSP_BASE"],
8
website: "base",
9
},
10
]
11
I want option like:
JavaScript
1
5
1
const tableDropdownOptions = [
2
{ value: "website1", label: "website1" },
3
{ value: "website2", label: "website2" },
4
];
5
Advertisement
Answer
Is that what you need? This pretty much is the same as your comment without the count.
JavaScript
1
11
11
1
const response = [{
2
"store": [],
3
"website": "storeuiteam"
4
}, {
5
"store": ["MSP_BASE"],
6
"website": "base"
7
}]
8
9
const options = response.map(item => ({ key: item.website, value: item.website }));
10
11
console.log(options)
EDIT
Here is a snippet that returns exactly the expected output
JavaScript
1
11
11
1
const response = [{
2
"store": [],
3
"website": "storeuiteam"
4
}, {
5
"store": ["MSP_BASE"],
6
"website": "base"
7
}]
8
9
const options = response.map((_, index) => ({ key: `website${index + 1}`, value: `website${index + 1}` }));
10
11
console.log(options)