JavaScript

JavaScript 两数组合并成数组对象

const ids = [1, 2, 3]
const names = ['foo', 'bar', 'baz']

const arr3 = ids.map((id, index) => ({ id, name: names[index] }))

输出结果:
[
  { id: 1, name: 'foo' },
  { id: 2, name: 'bar' }
  { id: 3, name: 'baz' }
]

xxx

const ids = [1, 2, 3]
const names = ['foo', 'bar', 'baz']

const arr3 = ids.map((id, index) => [id, names[index]])

输出结果:
[
  [1, 'foo']
  [2, 'bar']
  [3, 'baz']
]

Object.fromEntries(arr3)

输出结果:
{
  1: "foo",
  2: "bar",
  3: "baz"
}

JavaScript 数组对象去重