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);