How to remove a simple specific key value pair from all objects inside an array

user8758206

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

Sreeram Padmanabhan
objArr.forEach(a => delete a.theId);

Docs for delete operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How to get all values of objects inside array

분류에서Dev

how to create variables from key value object pair in javascript

분류에서Dev

Extract value from NSObject key/value pair

분류에서Dev

Convert array to Hashmap (key value pair) javascript

분류에서Dev

How to remove and re-add specific objects by id into Array [jQuery]

분류에서Dev

Recursively remove elements from nested array looking for a specific value

분류에서Dev

How to add a key,value pair to a list?

분류에서Dev

How to remove duplicate values from a multidimentional array according to a key

분류에서Dev

How to choose a random Value from Assoc array then display the key and value

분류에서Dev

jQuery AJAX - push additional key/value pair into a serialized $_POST array

분류에서Dev

How to remove all next elements from array in javascript or lodash

분류에서Dev

Remove array key from multidimensional array

분류에서Dev

How to get a specific array value from an XML File?

분류에서Dev

How to handle a file using key,value pair in shell script

분류에서Dev

What is a Key-Value Pair?

분류에서Dev

How to remove both instances of duplicated objects in an array

분류에서Dev

How to access attributes of php object inside a array of php objects from javascript

분류에서Dev

How to remove dictionary key with known value?

분류에서Dev

Remove whitespace from all array elements

분류에서Dev

Remove part of String that is inside a pair of hashes

분류에서Dev

How can I skip objects from a JSON file if the value of a key = 0?

분류에서Dev

How to remove an element from a dynamically allocated array of objects with operator -= without using std::vectors?

분류에서Dev

Remove Last Comma From Array Value in Loop

분류에서Dev

Remove value from array in magento field

분류에서Dev

how to remove specific String from String in java

분류에서Dev

How to remove object with specific name from ArrayList

분류에서Dev

how to remove specific String from String in java

분류에서Dev

How to remove fastclick from a specific element?

분류에서Dev

Javascript: extract objects from inside an array of objects, and put them into a new array

Related 관련 기사

  1. 1

    How to get all values of objects inside array

  2. 2

    how to create variables from key value object pair in javascript

  3. 3

    Extract value from NSObject key/value pair

  4. 4

    Convert array to Hashmap (key value pair) javascript

  5. 5

    How to remove and re-add specific objects by id into Array [jQuery]

  6. 6

    Recursively remove elements from nested array looking for a specific value

  7. 7

    How to add a key,value pair to a list?

  8. 8

    How to remove duplicate values from a multidimentional array according to a key

  9. 9

    How to choose a random Value from Assoc array then display the key and value

  10. 10

    jQuery AJAX - push additional key/value pair into a serialized $_POST array

  11. 11

    How to remove all next elements from array in javascript or lodash

  12. 12

    Remove array key from multidimensional array

  13. 13

    How to get a specific array value from an XML File?

  14. 14

    How to handle a file using key,value pair in shell script

  15. 15

    What is a Key-Value Pair?

  16. 16

    How to remove both instances of duplicated objects in an array

  17. 17

    How to access attributes of php object inside a array of php objects from javascript

  18. 18

    How to remove dictionary key with known value?

  19. 19

    Remove whitespace from all array elements

  20. 20

    Remove part of String that is inside a pair of hashes

  21. 21

    How can I skip objects from a JSON file if the value of a key = 0?

  22. 22

    How to remove an element from a dynamically allocated array of objects with operator -= without using std::vectors?

  23. 23

    Remove Last Comma From Array Value in Loop

  24. 24

    Remove value from array in magento field

  25. 25

    how to remove specific String from String in java

  26. 26

    How to remove object with specific name from ArrayList

  27. 27

    how to remove specific String from String in java

  28. 28

    How to remove fastclick from a specific element?

  29. 29

    Javascript: extract objects from inside an array of objects, and put them into a new array

뜨겁다태그

보관