score:1
Accepted answer
As @Nick's comment, the type of context
is an array. So you should access it by index
like below
var data = [
{
"id": "00000",
"type": "company",
"name": "Ideal-Phones",
"icon": "\uf1ad",
"level" :"0",
"display" : "block",
"context": [
{"context-id": "10000", "name": "phone"}
]
}
];
var firstItem = data[0].context;
console.log("Is array: " + Array.isArray(firstItem));
var firstContext_of_firstItem = firstItem[0];
console.log("Value: " + firstContext_of_firstItem.name);
More requirement: Loop and compare the name
of property
var data = [
{
"id": "00000",
"type": "company",
"name": "Ideal-Phones",
"icon": "\uf1ad",
"level" :"0",
"display" : "block",
"context": [
{"context-id": "10000", "name": "phone"},
{"context-id": "10001", "name": "Ideal-Phones"},
]
}
];
for(let item of data){
var name_of_item = item.name;
for(let childContext of item.context){
var name_of_child_context = childContext.name;
if(name_of_item === name_of_child_context){
// do something here
console.log(childContext);
}
}
}
score:0
This code will write to console the desired output "phone"
var txt = '[{\"id\":\"00000\",\"type\":\"company\",\"name\":\"Ideal-Phones\",\"icon\":\"\uf1ad\",\"level\":\"0\",\"display\":\"block\",\"context\":[{\"context-id\":\"10000\",\"name\":\"phone\"}]},{\"id\":\"00100\",\"type\":\"software\",\"name\":\"Jira\",\"icon\":\"\uf7b1\",\"parent\":\"00000\",\"level\":\"1\",\"display\":\"none\",\"context\":[{\"contxt-id\":\"10001\",\"name\":\"Jira\"}]}]'
var obj = JSON.parse(txt);
alert(obj[0].context[0].name);
Source: stackoverflow.com
Related Query
- Get JSON child data
- Get json data in d3 from lift snippet
- reformatted data into JSON from CSV, can't get parsing right in D3
- trying to get MySQL data into nested json file for d3?
- get data from external json with react and d3
- How do you get JSON data and create a line chart with d3.js?
- Cannot get treemap to render with new JSON data
- How to get a data from an analysis in R in Json file format to get D3 visualisations?
- Get data from JSON to D3.js
- Update page JSON data get on drop down change
- Create D3-friendly JSON out of Parent Child table of data
- How to get json data from controller in jsp?
- I can not get php produced json data with d3.json
- How do I structure data in php to get the correct json result?
- How to get parent node from child in json using d3js as Force Layout?
- Get data from mysql with json and plot with D3
- Can't get JSON data from file from local domain URL (Django static file)
- D3 get JSON data from mysql always returning undefined
- Where to get json data for map creation?
- d3 js - loading json without a http get
- How to get data of parent node in d3.js
- Loading D3.js data from a simple JSON string
- D3 - how to deal with JSON data structures?
- Updating links on a force directed graph from dynamic json data
- How/Where do I get geoJSON data for states, provinces, and administrative regions of non-US countries?
- D3.js: Get an array of the data attached to a selection?
- d3js: make new parent data descend into child nodes
- Generate (multilevel) flare.json data format from flat json
- d3 - reading JSON data instead of CSV file
- In d3, how to get the interpolated line data from a SVG line?
More Query from same tag
- How to change styling of a SVGCircleElement object?
- d3.js: Labels are not respecting their place (simple bar chart)
- d3 with Highchart Jasper Export Issue using Custom Visualization Component(CVC)
- D3.js: Placin' the text on the arcs of the doughnut chart
- Array manipulation with d3.nest and rollup
- Why does D3 circle position virtually reset after drag
- How to add text in the center of node in force directed graph?
- my d3 y axis overflow when text become long, how to break word in chart?
- Unable to display a JSON map using d3.js
- Is it better practice to use array of JSON objects or separate arrays in D3.js?
- How do I perform the equivalent of the .exit() from a previous version of d3.js to version 5.9.2?
- D3 How to keep element same size while transform scale / translate
- How to change the transition for angularjs-nvd3-directives charts
- Monochromatic color palette generation with d3 library
- d3.js array issues: Invalid value for <path> in line graph
- How can I change a heatmap from D3 in bicolor heatmap?
- d3.js: data binding with table and chart
- Retrieving selection's data
- Google API V3: How to remove overlay using Custom Overlay's onRemove() method
- D3 Line chart doesn't return correct value on ticks mouse over
- flat CSV to nested JSON tree for D3.js
- x3dom chart does not display using d3
- d3 line chart string as x axis domain
- Target this->sibling with mouse event
- Putting images as axis ticks in d3.js
- Calling specific data in an array created with rollup with d3.js
- Adding labels to a legend with dynamic colours
- d3.zoomIdentity.translate().scale() doesn't respect d3.zoom().translateExtent()
- Not able to create graph links/edges using networkx and d3
- Is there a way to tell crossfilter to treat elements of array as separate records instead of treating whole array as single key?