Loop a multidimensional array and only print two specific column values per row

Using a foreach loop without a key: foreach($array as $item) { echo $item[‘filename’]; echo $item[‘filepath’]; // To know what’s in $item echo ‘<pre>’; var_dump($item); } Using a foreach loop with a key: foreach($array as $i => $item) { echo $array[$i][‘filename’]; echo $array[$i][‘filepath’]; // $array[$i] is same as $item } Using a for loop: for ($i … Read more

Javascript: hiding prototype methods in for loop?

You can achieve desired outcome from the other end by making the prototype methods not enumerable: Object.defineProperty(Array.prototype, “containsKey”, { enumerable: false, value: function(obj) { for(var key in this) if (key == obj) return true; return false; } }); This usually works better if you have control over method definitions, and in particular if you have … Read more

Node.js – Using the async lib – async.foreach with object

The final function does not get called because async.forEach requires that you call the callback function for every element. Use something like this: async.forEach(Object.keys(dataObj), function (item, callback){ console.log(item); // print the key // tell async that that particular element of the iterator is done callback(); }, function(err) { console.log(‘iterating done’); });

Iterating over integer[] in PL/pgSQL

Postgres 9.1 added FOREACH to loop over arrays: DO $do$ DECLARE _arr int[] := ‘{1,2,3,4}’; _elem int; — matching element type BEGIN FOREACH _elem IN ARRAY _arr LOOP RAISE NOTICE ‘%’, _elem; END LOOP; END $do$; db<>fiddle here Works for multi-dimensional arrays, too: Postgres flattens the array and iterates over all elements. To loop over … Read more