-2

Currently my code is console.log("body:", body.readResults). But I do not want the value t and r. How to deselect them and get the rest?

"readResults": [
   {
       "id": "Channel1.Device1.Coil",
       "s": true,
       "r": "",
       "v": true,
       "t": 1553586722927
    }
]
lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
Ye Htet
  • 27
  • 1
  • 6
  • 2
    Format your code, take the [tour], and then reformulate your question so that it is understandable. – Script47 Mar 26 '19 at 09:36
  • what what will be there instead of `t` & `r`c – brk Mar 26 '19 at 09:38
  • 2
    Possible duplicate of [Javascript: Remove attribute for all objects in array](https://stackoverflow.com/questions/18133635/javascript-remove-attribute-for-all-objects-in-array) and [Remove specific properties from Array objects in Node.js](https://stackoverflow.com/questions/44888732) – adiga Mar 26 '19 at 09:42

1 Answers1

0

You can do it easily:

function cleanMyResult(result) {
    const cleanResult = Object.assign({}, result); // this will preserve your original object, but it costs some performance
    delete cleanResult.t;
    delete cleanResult.r;
    return cleanResult;
}

const cleanedResults = body.readResults.map(cleanMyResult);
console.log(cleanedResults);

Please check also a lot of already good answers available on SO:

lifeisfoo
  • 15,478
  • 6
  • 74
  • 115
  • @YaHtet good! So please accept my answer using the checkmark, so others will be able to understand quickly that your question was solved. – lifeisfoo Mar 28 '19 at 07:13