'how can i get the "validade" value from the array and get only?

The array

    {"status":true,"data":[{"id":1,"pessoa_id":75505,"created_at":"2022-02- 
    01T17:42:46.000000Z","holder":"LEONARDO LIMA","validade":"2026-06- 
    01","bandeira":"Mastercard"}]}

Inside digiAno I wanted to put only the year value of the array

this.dadosCC.reset({
  'parcelas': '1',
  'digiNumero': ['**** **** ****', cartao.mask] ,
  'digiNome': cartao.holder,
  'digiMes': '',
  'digiAno': cartao.validade,
  'valor': this.cartS.cart.valorTotal,
  'cpfInput': this.userS.user.cpf,
  'cardToken': this.cardToken,
  'digiCVV':''
 });


Solution 1:[1]

If you want to get the entire information of validade and put that information inside cartao use this code:

myObject: any = {
    "status": true,
    "data": [{
      "id": 1,
      "pessoa_id": 75505,
      "created_at": "2022-02-01T17:42:46.000000Z",
      "holder": "LEONARDO LIMA",
      "validade": "2026-06-01",
      "bandeira": "Mastercard"
    }]
  };

  cartao: any = this.myObject.data[0].validade;

If you want to get year, month and the day use this.

myObject: any = {
    "status": true,
    "data": [{
      "id": 1,
      "pessoa_id": 75505,
      "created_at": "2022-02-01T17:42:46.000000Z",
      "holder": "LEONARDO LIMA",
      "validade": "2026-06-01",
      "bandeira": "Mastercard"
    }]
  };

  cartao: any = this.myObject.data[0].validade;

  dateArray: any = this.cartao.split('-');
  
  year = this.dateArray[0];
  month = this.dateArray[1];
  day = this.dateArray[2];

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jose Vicente