从Javascript对象中删除不需要的KEy?

时间:2019-05-23 05:14:28

标签: javascript arrays vue.js graphql javascript-objects

我说的是充满对象的数组:

console.log(Array.from([4,7,9], (x, i) => `index ${i} : ${x}`))

我想知道是否有可能从每个对象中删除不需要的边缘和节点,以使前端的点符号减少吗?

理想情况下,我希望它看起来像

Hi Ravindu ,

I think you are putting username and password in header and body as well.
it worked for me as below.

login(username, password) {

    const headers = {
            'Authorization': 'Basic ' + btoa('devglan-client:$2a$04$e/c1/RfsWuThaWFCrcCuJeoyvwCV0URN/6Pn9ZFlrtIWaU/vj/BfG'),
            'Content-type': 'application/x-www-form-urlencoded'
          }

    const body = new HttpParams()
      .set('username', username)
      .set('password', password)
      .set('grant_type', 'password');

      this.http.post('http://localhost:8080/' + 'oauth/token', body, {headers})
      .subscribe(data => this.setToken(data),
      err => alert('invalid Creadtilas'));

    }

1 个答案:

答案 0 :(得分:1)

您输入的数据不正确。您不能在JSON数据结构中的同一级别上重复键。以下答案是对数据结构的修改。

const data = [
  {
    ID: 1, 
    Subject: 
      {
        edge : [
          {node: {ID : 1, Title: "English"}}
        ]
      }
  }, 
  {
    ID: 2, 
    Subject: {
        edge: [
           {node: {ID: 1, Title: "Maths"}}
        ]
     }
  }
];

const result = data.map(x => ({...x, Subject: x.Subject.edge[0].node}));
console.log(result);