ket*_*han 1 javascript angularjs
[
{ "text": "demo1" },
{ "text": "demo2" }
]
Run Code Online (Sandbox Code Playgroud)
至
["demo1", "demo2"]
Run Code Online (Sandbox Code Playgroud)
我尝试过使用reduce()
你可以用Array.prototype.map它:
var arr = [
{"text":"demo1"},
{"text":"demo2"}
];
var texts = arr.map(function(el) {
return el.text;
});
console.log(texts);Run Code Online (Sandbox Code Playgroud)
使用ES6,您可以使用箭头功能:
var texts = arr.map((el) => el.text);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4277 次 |
| 最近记录: |