I have a JSON array:
[
{
"art": "A",
"count": "0",
"name": "name1",
"ean": "802.0079.127",
"marker": "null",
"stammkost": "A",
"tablename": "IWEO_IWBB_01062015"
},
{
"art": "A",
"count": "0",
"name": "2",
"ean": "657.7406.559",
"marker": "null",
"stammkost": "A",
"tablename": "IWEO_IWBB_02062015"
}
]
To iterate over the array in PHP I would use the following code to iterate over the tablenames:
foreach($jArray as $value){
$tablename = $value['tablename'];
//some code
}
How can I do this in Node.js? I found many questions with it, but no actual answer. Most of them are from 2011.
To iterate JSON array, use the JSON. parse().
Use Object.values() or Object. entries(). These will return an array which we can then iterate over. Note that the const [key, value] = entry; syntax is an example of array destructuring that was introduced to the language in ES2015.
The map() method is the most commonly used function to iterate over an array of data in JSX. You can attach the map() method to the array and pass a callback function that gets called for each iteration. When rendering the User component, pass a unique value to the key prop.
var tables = [
{ "art":"A","count":"0","name":"name1","ean":"802.0079.127","marker":"null","stammkost":"A","tablename":"IWEO_IWBB_01062015" },
{ "art":"A","count":"0","name":"2","ean":"657.7406.559","marker":"null","stammkost":"A","tablename":"IWEO_IWBB_02062015" }
];
tables.forEach(function(table) {
var tableName = table.name;
console.log(tableName);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With