[英]How to return array of objects from two arrays
I have two arrays:我有两个 arrays:
a1= ['All', 'one', 'two'];
a2= ['Users', 'Service', 'Admin'];
I need to return an array of object like this我需要像这样返回一个 object 的数组
[
{value: 'All', label: 'Users'},
{value: 'one', label: 'Service'},
{value: 'two', label: 'Admin'}
]
Can somebody help?有人可以帮忙吗?
Try this:尝试这个:
const a1 = ['All', 'one', 'two'];
const a2 = ['Users', 'Service', 'Admin'];
a1.map((item, index) => ({
value: item,
label: a2[index]
}))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.