Здесь вы go с помощью решения map
var json = [
{
"key": "A",
"label": "Question 1",
"value": "Test",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Test"
],
"assignedToProcessInput": false,
"confidential": false
},
{
"key": "B",
"label": "Question 2",
"value": "Ignore",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Ignore"
],
"assignedToProcessInput": false,
"confidential": false
}
];
json.map(item => {
console.log(item.label, ": ", item.value );
});
Если вы хотите сохранить сообщение, используйте код ниже
var json = [
{
"key": "A",
"label": "Question 1",
"value": "Test",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Test"
],
"assignedToProcessInput": false,
"confidential": false
},
{
"key": "B",
"label": "Question 2",
"value": "Ignore",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Ignore"
],
"assignedToProcessInput": false,
"confidential": false
}
];
var msgVal = [];
json.map(item => {
msg.push({
label: item.label,
value: item.value
);
});
console.log(msg);
Обновленное решение
[
{
"key": "A",
"label": "Question 1",
"value": "Test",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Test"
],
"assignedToProcessInput": false,
"confidential": false
},
{
"key": "B",
"label": "Question 2",
"value": "Ignore",
"tags": [],
"valueType": "TEXT",
"displayValue": [
"Ignore"
],
"assignedToProcessInput": false,
"confidential": false
}
]
$..label