gpt4 book ai didi

javascript - 如何将数组数组重组为对象数组

转载 作者:行者123 更新时间:2023-12-02 16:05:49 24 4
gpt4 key购买 nike

我需要帮助构建新的 json 对象数组。我从一个数组开始。我需要最终得到一系列对象。 javascript 或 linq.js 将完美运行。谢谢

这就是我要开始的

var needtoChangeThisArray = [
[1558, 219561],
[2520, 438218],
[3482, 656874],
[4444, 875531],
[5406, 1094187]
];

这就是数组的结构

var needsToLookLikeThisArray = [
{
"name": "Arbor Vista - Arbor Custom Homes",
"subId": "10394",
"bldId": "8598"
}, {
"name": "Arbor Vista - DR Horton - (OR)",
"subId": "10394", "bldId": "8597"
}, {
"name": "Copper Canyon Estates - Brentwood Homes",
"subId": "9048",
"bldId": "16737"
}`enter code here`
];

所以我需要结束这个

var needToEndUpWithThisArray = [
{
"sqft": "1558",
"price": "219561"
}, {
"sqft": "2520",
"price": "438218"
}, {
"sqft": "3482",
"price": "656874"
}, {
"sqft": "4444",
"price": "875531"
}, {
"sqft": "5406",
"price": "1094187"
}
];

最佳答案

这足够了吗?

needToEndUpWithThisArray = needtoChangeThisArray.map(function(a) {
return {
sqft: a[0],
price: a[1]
};
});

关于javascript - 如何将数组数组重组为对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30759180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com