gpt4 book ai didi

javascript - 将对象数组转换为字符串数组

转载 作者:行者123 更新时间:2023-12-04 01:35:22 26 4
gpt4 key购买 nike

[
{ "text": "demo1" },
{ "text": "demo2" }
]


["demo1", "demo2"]

我试过使用 reduce()

最佳答案

您可以使用 Array.prototype.map 为了那个原因:

var arr = [
{"text":"demo1"},
{"text":"demo2"}
];
var texts = arr.map(function(el) {
return el.text;
});
console.log(texts);


使用 ES6,你可以使用 arrow functions :
var texts = arr.map((el) => el.text);

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

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