JSFiddle - React, Tailwind, and code Playground

by acdcjunior

JavaScript

var tags = ["Favorite", "Starred", "High Rated"];
tags.gotcha = 'GOTCHA!'; // here so you see it will not be printed

for (var i = 0; i < tags.length; i++) { // proper way to iterate an array
    console.log(tags[i]);
}


var tags2 = {"Favorite": "some", "Starred": "stuff", "High Rated": "here"};
for (var tag in tags2) { // enumerating objects properties
    console.log("My property: " + tag +"'s value is " +tags2[tag]);
}


var tags3 = ["Favorite", "Starred", "High Rated"];
tags3.gotcha = 'GOTCHA!'; // not an item of the array

// they can be set globally too, affecting all arrays without you noticing:
Array.prototype.otherGotcha = "GLOBAL!";

for (var tag in tags3) {
    console.log("Side effect: "+ tags3[tag]);
}