<分区>
我正在学习 ES6 和对象,想知道如何去掉这个对象数组中的一对键值对:
[
{ "name" : "mark", "height" : "tall", "theId" : "1", "nat" : "uk"},
{ "name" : "ben", "height" : "medium", "theId" : "2", "nat" : "uk"},
{ "name" : "neil", "height" : "small", "theId" : "3", "nat" : "uk" }
]
结果应该是:
[
{ "name" : "mark", "height" : "tall", "nat" : "uk"},
{ "name" : "ben", "height" : "medium", "nat" : "uk"},
{ "name" : "neil", "height" : "small", "nat" : "uk" }
]
我创建了一个 forEach 函数并尝试将每个结果推送到一个新数组中,但现在没有任何对象。
如何解决这个问题?或者有没有更好的方法使用 ES6/ES7 语法来做到这一点?谢谢你的帮助。代码和codePen URL如下:
代码笔:https://codepen.io/anon/pen/bPYQyb
let objArr = [
{ "name" : "mark", "height" : "tall", "theId" : "1", "nat" : "uk"},
{ "name" : "ben", "height" : "medium", "theId" : "2", "nat" : "uk"},
{ "name" : "neil", "height" : "small", "theId" : "3", "nat" : "uk" }
],
arr = [];
objArr.forEach(function(obj) {
for (let column in obj) {
let currArr = [];
if (isNaN(obj[column])) {
console.log('true');
currArr.push(obj[column]);
}
arr.push(currArr);
}
});
console.log(arr);