首页 > 解决方案 > 将数组转换为没有键的对象

问题描述

我正在寻找一种方法来转换它。

    const data = [{
                id: 1,
                fullnames: 'JosephSam',
                weight: 1231,
                currentdate: '2021-09-22'
    }]

进入这个

        const data = {
                id: 1,
                fullnames: 'JosephSam',
                weight: 1231,
                currentdate: '2021-09-22'
    }

标签: javascriptarraysreactjsobject

解决方案


const arr = [{
            id: 1,
            fullnames: 'JosephSam',
            weight: 1231,
            currentdate: '2021-09-22'
}];

const data = arr[0];

console.log(data.fullnames); // 'JosephSam'

这将是你所需要的。我确实觉得这不是你要找的。如果是这样,请给我们一个更复杂的例子,看看你在处理什么。


推荐阅读