Get loop counter/index using for…of syntax in JavaScript

for…in iterates over property names, not values, and does so in an unspecified order (yes, even after ES6). You shouldn’t use it to iterate over arrays. For them, there’s ES5’s forEach method that passes both the value and the index to the function you give it: var myArray = [123, 15, 187, 32]; myArray.forEach(function (value, … Read more

Last iteration of enhanced for loop in java

Another alternative is to append the comma before you append i, just not on the first iteration. (Please don’t use “” + i, by the way – you don’t really want concatenation here, and StringBuilder has a perfectly good append(int) overload.) int[] array = {1, 2, 3…}; StringBuilder builder = new StringBuilder(); for (int i … Read more

How to remove element from array in forEach loop?

It looks like you are trying to do this? Iterate and mutate an array using Array.prototype.splice var pre = document.getElementById(‘out’); function log(result) { pre.appendChild(document.createTextNode(result + ‘\n’)); } var review = [‘a’, ‘b’, ‘c’, ‘b’, ‘a’]; review.forEach(function(item, index, object) { if (item === ‘a’) { object.splice(index, 1); } }); log(review); <pre id=”out”></pre> Which works fine for … Read more

What does [].forEach.call() do in JavaScript?

[] is an array. This array isn’t used at all. It’s being put on the page, because using an array gives you access to array prototypes, like .forEach. This is just faster than typing Array.prototype.forEach.call(…); Next, forEach is a function which takes a function as an input… [1,2,3].forEach(function (num) { console.log(num); }); …and for each … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)