简体   繁体   English

如何从两个 arrays 返回对象数组

[英]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.

相关问题 如何从对象数组返回条件 arrays? - How to return conditional arrays from an array of objects? 遍历两个数组并返回对象数组 - Iterate over two arrays and return an array of objects 如何将两个 arrays 组合成具有来自每个数组的数据的多个对象? - How to combine two arrays into multiple objects with data from each array? 从两个不同的数组创建对象数组 - Create an array of objects from two different arrays 从JavaScript中的两个数组生成对象数组 - Generate array of objects from two arrays in JavaScript Angular - 比较两个 arrays 具有相同数量的对象但具有不同的值,并返回与第二个数组的差异 - Angular - Compare two arrays with same number of objects but with different values and return the difference from second array 如何在javascript中将两个数组组合成一个对象数组? - How to combine two arrays into an array of objects in javascript? 如何使用array.map方法从数组数组返回对象数组? - How to return an array of objects from array of arrays with array.map method? 比较两个 Arrays 对象,如果 Javascript 中的值为真,则返回一个新数组 - Compare Two Arrays Of Objects and return a new array if value is true in Javascript JavaScript 如何通过两个不同的 arrays 对象并有条件地返回一个数组 - JavaScript how to map through two different arrays of objects and return one array conditionally
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM