Get element from json array javascriptHow do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?Can comments be used in JSON?How can I convert a string to boolean in JavaScript?What is the correct JSON content type?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
How to align and center standalone amsmath equations?
From/by (what sounds better?)
Diode in opposite direction?
Varistor? Purpose and principle
Customize circled numbers
Is it possible to have a strip of cold climate in the middle of a planet?
A social experiment. What is the worst that can happen?
Reply ‘no position’ while the job posting is still there (‘HiWi’ position in Germany)
How should I respond when I lied about my education and the company finds out through background check?
How do I extrude a face to a single vertex
Female=gender counterpart?
THT: What is a squared annular “ring”?
Bob has never been a M before
Indicating multiple different modes of speech (fantasy language or telepathy)
How will losing mobility of one hand affect my career as a programmer?
In Star Trek IV, why did the Bounty go back to a time when whales were already rare?
Why did the EU agree to delay the Brexit deadline?
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Make "apt-get update" show the exact output as `apt update`
Did arcade monitors have same pixel aspect ratio as TV sets?
What is the smallest body in which a sling shot maneuver can be performed?
How do I repair my stair bannister?
Has Darkwing Duck ever met Scrooge McDuck?
Some numbers are more equivalent than others
Get element from json array javascript
How do JavaScript closures work?What is the most efficient way to deep clone an object in JavaScript?How do I check if an element is hidden in jQuery?How do I remove a property from a JavaScript object?Can comments be used in JSON?How can I convert a string to boolean in JavaScript?What is the correct JSON content type?How to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
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
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
1
You can useJSON.parseto convert json to object.
– Eddie
1 hour ago
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 1 hour ago
Jack Bashford
13.1k31847
13.1k31847
asked 1 hour ago
Java Dev BeginnerJava Dev Beginner
6318
6318
1
You can useJSON.parseto convert json to object.
– Eddie
1 hour ago
add a comment |
1
You can useJSON.parseto convert json to object.
– Eddie
1 hour ago
1
1
You can use
JSON.parse to convert json to object.– Eddie
1 hour ago
You can use
JSON.parse to convert json to object.– Eddie
1 hour ago
add a comment |
8 Answers
8
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
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
1 hour ago
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 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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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 try with Array.prototype.map()
The
map()method creates a new array with the results of calling a provided function on every element in the calling array.
JSON.parse()
The
JSON.parse()method parses a JSON string, constructing the JavaScript value or object described by the string.
and Array.prototype.flat()
The
flat()method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
like the following way:
var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333968%2fget-element-from-json-array-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
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 1 hour ago
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 1 hour ago
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
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
1 hour ago
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
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
1 hour ago
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 1 hour ago
R3tepR3tep
8,00982962
8,00982962
@Deepakguptadata[0]is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
1 hour ago
add a comment |
@Deepakguptadata[0]is not a string, the array is parsed before. See the live demo before post a comment
– R3tep
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the keyvalueInput
– R3tep
1 hour ago
@Deepakgupta
data[0] is not a string, the array is parsed before. See the live demo before post a comment– R3tep
1 hour ago
@Deepakgupta
data[0] is not a string, the array is parsed before. See the live demo before post a comment– R3tep
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
the input value is a string, not an object, and the string is not correctly stringified.
– AZ_
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
@AZ_ The input value is not a string. Jack make some bad edit
– R3tep
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
it says I have a simple Json String not sure maybe.
– AZ_
1 hour ago
@AZ_ Yes he have a json string into the key
valueInput– R3tep
1 hour ago
@AZ_ Yes he have a json string into the key
valueInput– R3tep
1 hour ago
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 1 hour ago
Jack BashfordJack Bashford
13.1k31847
13.1k31847
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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);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"]"
];
const namesArr = JSON.parse(arr[0].valueInput).data.map(o => o.name);
console.log(namesArr);answered 1 hour ago
Yosvel QuinteroYosvel Quintero
11.9k42531
11.9k42531
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 1 hour ago
brkbrk
29.1k32243
29.1k32243
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 1 hour ago
Kabelo TookaKabelo Tooka
186110
186110
add a comment |
add a comment |
You can try with Array.prototype.map()
The
map()method creates a new array with the results of calling a provided function on every element in the calling array.
JSON.parse()
The
JSON.parse()method parses a JSON string, constructing the JavaScript value or object described by the string.
and Array.prototype.flat()
The
flat()method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
like the following way:
var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);add a comment |
You can try with Array.prototype.map()
The
map()method creates a new array with the results of calling a provided function on every element in the calling array.
JSON.parse()
The
JSON.parse()method parses a JSON string, constructing the JavaScript value or object described by the string.
and Array.prototype.flat()
The
flat()method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
like the following way:
var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);add a comment |
You can try with Array.prototype.map()
The
map()method creates a new array with the results of calling a provided function on every element in the calling array.
JSON.parse()
The
JSON.parse()method parses a JSON string, constructing the JavaScript value or object described by the string.
and Array.prototype.flat()
The
flat()method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
like the following way:
var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);You can try with Array.prototype.map()
The
map()method creates a new array with the results of calling a provided function on every element in the calling array.
JSON.parse()
The
JSON.parse()method parses a JSON string, constructing the JavaScript value or object described by the string.
and Array.prototype.flat()
The
flat()method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
like the following way:
var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);var data = [
"assetName":"LCT",
"assetValue":"",
"typeValueInput":"select",
"valueInputSelect":null,
"required":true,
"valueInput":""data":["name":"name1","id":"12","name":"name2","id":"13","name":"name3","id":"14"]"
]
var fieldNames = data.map(d => JSON.parse(d.valueInput).data.map(i => i.name)).flat(2);
console.log(fieldNames);edited 1 hour ago
answered 1 hour ago
MamunMamun
29.8k71931
29.8k71931
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55333968%2fget-element-from-json-array-javascript%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
You can use
JSON.parseto convert json to object.– Eddie
1 hour ago