How to loop through json response in javascript? [duplicate] - javascript

This question already has answers here:
Safely turning a JSON string into an object
(28 answers)
Why is using "for...in" for array iteration a bad idea?
(28 answers)
Loop through an array in JavaScript
(46 answers)
JavaScript loop through JSON array?
(14 answers)
Closed 2 years ago.
Note: I have already gone through stackoverflow similar questions but without any luck.
I have following json response received in ajax. I am trying to loop through it but still no success.
[
{"id":"1","type":"size","value":"large","datetime":"2020-10-20 13:45:49"},
{"id":"14","type":"color","value":"red","datetime":"2020-10-20 13:45:49"}
]
I tried many ways including following code but could not get desired result.
for( let prop in responce ){
console.log( responce[prop].id );
}
for( let prop in responce ){
console.log( responce[prop] );
}
Kindly advise how to resolve it?

Related

cannot print component in array in javascript [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
How do I reference a JavaScript object property with a hyphen in it?
(11 answers)
Closed 2 months ago.
i'm just a newbie on javascript , please help me this
var arr = [{"student-name":"Harry Potter","discipline":"Magic"}] ;
how can i get "Harry Potter" in this array , thanks for helping

How to read JSON with multiple key value pair [duplicate]

This question already has answers here:
How to parse JSON data with jQuery / JavaScript?
(11 answers)
Closed 4 years ago.
On AJAX request response is following :
[ {"status":{"login":"invalid"}},
{"user":{"username":false,"pwd":false}}
]
How to read values in Jquery.
Use JSON.parse(string) to get an Object.
After that you can access values as default:
var json = JSON.parse(res.data)
console.log(json.status.login)

Get and output JSON [duplicate]

This question already has answers here:
Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference
(7 answers)
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 5 years ago.
I know this propably got answered very often but I still don't get it.
The only information I need is "up" and "down".
I got some JSON API Data and just want to get some specific data from it and just output it via alert().
What I got:
$.getJSON('URL', function(data) {
jsonData = data;
});
alert(data['items'][0]['up'][0]);
What the JSON looks like:
I tried to do this with the help of the mozilla wiki...

Get all data from JSON array [duplicate]

This question already has answers here:
Loop (for each) over an array in JavaScript
(40 answers)
Closed 7 years ago.
I've a little problem with a simple thing.I believe.
this is my code...
javascript code
I'm able to grab the first object element but I need all the data object, I guess I've to change something in this code line...
value[0]['firstName'];
You need to replace
value[0]['firstName']; // $.each()
With
value[index]['firstName']; // $.each()
And
$.each(oggprova.PIANIFI,function(){...});
with
$.each(oggprova.PIANIFI.gennio,function(){....});

Underscore.js get value of key object in array of object [duplicate]

This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 7 years ago.
i have to get the value of wave1 and wave2 from array by using underscore.js
array =[{"id":1,"name":"Monoprix", "pdv":16,"graph":[{"wave1":22,"wave2":11}]} ;
i try
$scope.wave1 =array.graph.wave1 ;
console.log($scope.wave1) ;
console log = Unidentified
can you help me !
your code is wrong, you miss ] after element list.
your array :
var array =[{"id":1,"name":"Monoprix", "pdv":16,"graph":[{"wave1":22,"wave2":11}]}];
and to get some data you must first select array index, like this:
array[0].graph

Categories