Get element from json array javascript [on hold]
I have a simple Json String
[
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
I want get field Name in Data in ValueInput by Javascript.
Please help me!
javascript arrays json object
put on hold as off-topic by CertainPerformance, pirho, wscourge, Kristopher Ives, Bart 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – pirho, wscourge, Kristopher Ives, Bart
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a simple Json String
[
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
I want get field Name in Data in ValueInput by Javascript.
Please help me!
javascript arrays json object
put on hold as off-topic by CertainPerformance, pirho, wscourge, Kristopher Ives, Bart 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – pirho, wscourge, Kristopher Ives, Bart
If this question can be reworded to fit the rules in the help center, please edit the question.
1
You can useJSON.parse
to convert json to object.
– Eddie
yesterday
2
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday
add a comment |
I have a simple Json String
[
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
I want get field Name in Data in ValueInput by Javascript.
Please help me!
javascript arrays json object
I have a simple Json String
[
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
I want get field Name in Data in ValueInput by Javascript.
Please help me!
javascript arrays json object
javascript arrays json object
edited yesterday
Jack Bashford
13.3k31847
13.3k31847
asked yesterday
Java Dev BeginnerJava Dev Beginner
6018
6018
put on hold as off-topic by CertainPerformance, pirho, wscourge, Kristopher Ives, Bart 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – pirho, wscourge, Kristopher Ives, Bart
If this question can be reworded to fit the rules in the help center, please edit the question.
put on hold as off-topic by CertainPerformance, pirho, wscourge, Kristopher Ives, Bart 19 hours ago
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example." – pirho, wscourge, Kristopher Ives, Bart
If this question can be reworded to fit the rules in the help center, please edit the question.
1
You can useJSON.parse
to convert json to object.
– Eddie
yesterday
2
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday
add a comment |
1
You can useJSON.parse
to convert json to object.
– Eddie
yesterday
2
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday
1
1
You can use
JSON.parse
to convert json to object.– Eddie
yesterday
You can use
JSON.parse
to convert json to object.– Eddie
yesterday
2
2
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday
add a comment |
7 Answers
7
active
oldest
votes
You need to loop through the array and then parse the stringified JSON so that you can access the data
array. Then simply loop that data
array to get the value of each name
property.
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
add a comment |
You could use JSON.parse
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
add a comment |
You can use JSON.parse
JSON.parse(o[0].valueInput).data[0].name
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
@Deepakguptadata[0]
is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
yesterday
add a comment |
Use JSON.parse
, and use map
:
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
add a comment |
You can use an array
variable and the callback function of JSON.parse
to get the name key
& val
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
add a comment |
Here is a way to do it.
let originalData = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
];
let valueInput = JSON.parse(originalData[0].valueInput);
let data = valueInput.data;
console.log(data);
for (var i = 0; i < data.length; i++){
console.log(data[i].name);
}
See jsfiddle https://jsfiddle.net/3s1na4eL/3/
Let me know if there are any questions.
add a comment |
You can do:
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
add a comment |
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
You need to loop through the array and then parse the stringified JSON so that you can access the data
array. Then simply loop that data
array to get the value of each name
property.
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
add a comment |
You need to loop through the array and then parse the stringified JSON so that you can access the data
array. Then simply loop that data
array to get the value of each name
property.
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
add a comment |
You need to loop through the array and then parse the stringified JSON so that you can access the data
array. Then simply loop that data
array to get the value of each name
property.
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
You need to loop through the array and then parse the stringified JSON so that you can access the data
array. Then simply loop that data
array to get the value of each name
property.
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
var arr = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
arr.forEach((arrObj) => {
var jsonData = JSON.parse(arrObj.valueInput);
jsonData.data.forEach(({name}) => console.log(name));
});
answered yesterday
Ankit AgarwalAnkit Agarwal
24.3k52245
24.3k52245
add a comment |
add a comment |
You could use JSON.parse
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
add a comment |
You could use JSON.parse
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
add a comment |
You could use JSON.parse
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
You could use JSON.parse
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
var jsonArray = [
{
assetName: 'LCT',
assetValue: '',
typeValueInput: 'select',
valueInputSelect: null,
required: true,
valueInput:
'{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}'
}
];
let name = jsonArray[0].valueInput;
name = JSON.parse(name);
name.data.forEach(value => {
console.log(value.name, value.id);
});
answered yesterday
Loc MaiLoc Mai
4113
4113
add a comment |
add a comment |
You can use JSON.parse
JSON.parse(o[0].valueInput).data[0].name
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
@Deepakguptadata[0]
is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
yesterday
add a comment |
You can use JSON.parse
JSON.parse(o[0].valueInput).data[0].name
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
@Deepakguptadata[0]
is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
yesterday
add a comment |
You can use JSON.parse
JSON.parse(o[0].valueInput).data[0].name
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
You can use JSON.parse
JSON.parse(o[0].valueInput).data[0].name
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
var o = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
]
console.log(JSON.parse(o[0].valueInput).data[0].name);
// To get all, use a loop
var arrO = JSON.parse(o[0].valueInput).data;
arrO.forEach((obj) => console.log(obj.name))
answered yesterday
R3tepR3tep
8,01782962
8,01782962
@Deepakguptadata[0]
is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
yesterday
add a comment |
@Deepakguptadata[0]
is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
yesterday
@Deepakgupta
data[0]
is not a string, the array is parsed before. See the live demo before post a comment– R3tep
yesterday
@Deepakgupta
data[0]
is not a string, the array is parsed before. See the live demo before post a comment– R3tep
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
yesterday
1
1
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
it says I have a simple Json String not sure maybe.
– AZ_
yesterday
@AZ_ Yes he have a json string into the key
valueInput
– R3tep
yesterday
@AZ_ Yes he have a json string into the key
valueInput
– R3tep
yesterday
add a comment |
Use JSON.parse
, and use map
:
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
add a comment |
Use JSON.parse
, and use map
:
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
add a comment |
Use JSON.parse
, and use map
:
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
Use JSON.parse
, and use map
:
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
const data = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}]
const names = JSON.parse(data[0].valueInput).data.map(({ name }) => name);
console.log(names);
answered yesterday
Jack BashfordJack Bashford
13.3k31847
13.3k31847
add a comment |
add a comment |
You can use an array
variable and the callback function of JSON.parse
to get the name key
& val
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
add a comment |
You can use an array
variable and the callback function of JSON.parse
to get the name key
& val
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
add a comment |
You can use an array
variable and the callback function of JSON.parse
to get the name key
& val
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
You can use an array
variable and the callback function of JSON.parse
to get the name key
& val
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
let dt = [{
"assetName": "LCT",
"assetValue": "",
"typeValueInput": "select",
"valueInputSelect": null,
"required": true,
"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}];
let nameArray = ;
let dlt = JSON.parse(dt[0].valueInput, function(key, val) {
if (key === 'name') {
nameArray.push(val);
}
})
console.log(nameArray)
answered yesterday
brkbrk
29.3k32244
29.3k32244
add a comment |
add a comment |
Here is a way to do it.
let originalData = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
];
let valueInput = JSON.parse(originalData[0].valueInput);
let data = valueInput.data;
console.log(data);
for (var i = 0; i < data.length; i++){
console.log(data[i].name);
}
See jsfiddle https://jsfiddle.net/3s1na4eL/3/
Let me know if there are any questions.
add a comment |
Here is a way to do it.
let originalData = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
];
let valueInput = JSON.parse(originalData[0].valueInput);
let data = valueInput.data;
console.log(data);
for (var i = 0; i < data.length; i++){
console.log(data[i].name);
}
See jsfiddle https://jsfiddle.net/3s1na4eL/3/
Let me know if there are any questions.
add a comment |
Here is a way to do it.
let originalData = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
];
let valueInput = JSON.parse(originalData[0].valueInput);
let data = valueInput.data;
console.log(data);
for (var i = 0; i < data.length; i++){
console.log(data[i].name);
}
See jsfiddle https://jsfiddle.net/3s1na4eL/3/
Let me know if there are any questions.
Here is a way to do it.
let originalData = [
{
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":"{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"
}
];
let valueInput = JSON.parse(originalData[0].valueInput);
let data = valueInput.data;
console.log(data);
for (var i = 0; i < data.length; i++){
console.log(data[i].name);
}
See jsfiddle https://jsfiddle.net/3s1na4eL/3/
Let me know if there are any questions.
answered yesterday
Kabelo TookaKabelo Tooka
186110
186110
add a comment |
add a comment |
You can do:
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
add a comment |
You can do:
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
add a comment |
You can do:
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
You can do:
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
const arr = [{"assetName": "LCT","assetValue": "","typeValueInput": "select","valueInputSelect": null,"required": true,"valueInput": "{"data":[{"name":"name1","id":"12"},{"name":"name2","id":"13"},{"name":"name3","id":"14"}]}"}];
arr.forEach(o => JSON.parse(o.valueInput).data.forEach(({id, name}) => console.log(id, name)));
edited 9 hours ago
answered yesterday
Yosvel QuinteroYosvel Quintero
11.9k42531
11.9k42531
add a comment |
add a comment |
1
You can use
JSON.parse
to convert json to object.– Eddie
yesterday
2
Why does this have seven upvotes? It does not show any effort made by the OP. What did they try? What did not work? stackoverflow.com/help/how-to-ask
– Denny
yesterday