JS extracts the Json array to get the key: "value"

This article does not take the key or value , but the key needed for extraction: "value" [must be a single array, if multiple sets of data need a for loop]

// row is a json string!!!

1. I have a single json [row] as long as the id and appStatus are separated into new arrays

insert image description here

    let list = [];
    for (var key in row) {
    
    
      var temp = {
    
    }
      if (key == "id") {
    
    
        temp.id = row[key]
        list.push(temp)
      } if (key == 'appStatus') {
    
    
        temp.appStatus = row[key]
        list.push(temp)
      }
    }
    console.log(list)

insert image description here

2. I have a single json [row] as long as the id and appStatus are not separated together

Method 1: Use numbers in row[0] brackets to get the corresponding key: "value"
Method 2: Customize

   var satusJson = {
    
    
           "id": row.id,
           "appStatus": row.appStatus,
       }
   console.log(satusJson)

insert image description here

3. I have a single json [row] except for id and appStatus.

const {
    
     id, appStatus, ...param } = row;
console.log(param); 

insert image description here

Guess you like

Origin blog.csdn.net/Start_Simple/article/details/130322342