I'm learning ES6 and objects and want to know how to get rid of one key-value pair in this array of objects:
[
{ "name" : "mark", "height" : "tall", "theId" : "1", "nat" : "uk"},
{ "name" : "ben", "height" : "medium", "theId" : "2", "nat" : "uk"},
{ "name" : "neil", "height" : "small", "theId" : "3", "nat" : "uk" }
]
The result should be:
[
{ "name" : "mark", "height" : "tall", "nat" : "uk"},
{ "name" : "ben", "height" : "medium", "nat" : "uk"},
{ "name" : "neil", "height" : "small", "nat" : "uk" }
]
I created a forEach function and tried to push each result into a new array, but now there are no objects.
How can this be fixed? Or is there a better way of doing this with the ES6/ES7 syntax? Thanks for any help. The code and codePen URL are below:
Codepen: 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);
objArr.forEach(a => delete a.theId);
Docs for delete operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다