gpt4 book ai didi

javascript - angularjs 将 json 对象转换为数组

转载 作者:行者123 更新时间:2023-11-28 12:18:26 24 4
gpt4 key购买 nike

嗨,我有这样的 json 返回对象

color_selected = [
{ id: 4},
{ id: 3}
];

如何将其转换为

color_selected = [4,3]

感谢您的帮助和建议

最佳答案

你可以像这样迭代它:

var newArray = [];
for(var i = 0; i < color_selected.length; i++) {
newArray.push(color_selected[i].id);
}

关于javascript - angularjs 将 json 对象转换为数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43943202/

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