Son*_*u K 3 arrays jquery json
我有一个以下格式的 json 数组:
[
{
"id":"01",
"language": "Java",
"edition": "third",
"author": "Herbert Schildt"
},
{
"id":"07",
"language": "C++",
"edition": "second"
"author": "E.Balagurusamy"
}
]
Run Code Online (Sandbox Code Playgroud)
我想要一个仅包含该数组中第一列的结果,格式如下:
[ "01", "07" ]
Run Code Online (Sandbox Code Playgroud)
我尝试了很多代码但没有成功,有没有办法使用 jquery 来实现这一点。
您可以像下面的 using 函数一样进行操作map()。
var input = [
{
"id": "01",
"language": "Java",
"edition": "third",
"author": "Herbert Schildt"
},
{
"id": "07",
"language": "C++",
"edition": "second",
"author": "E.Balagurusamy"
}
];
var result = $(input).map(function() {
return this.id;
}).get()
console.log(result);
Run Code Online (Sandbox Code Playgroud)