javascript in
by peterbenoit
JavaScript
// Arrays
var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
console.log(0 in trees); // returns true
console.log(3 in trees); // returns true
console.log(6 in trees); // returns false
console.log("bay" in trees); // returns false (you must specify the index number,
// not the value at that index)
console.log("length" in trees); // returns true (length is an Array property)
// Predefined objects
console.log("PI" in Math);
// Custom objects
var mycar = {make: "Honda", model: "Accord", year: 1998};
console.log("make" in mycar); // returns true
console.log("model" in mycar); // returns true
// using with deleted properties
var mycar = {make: "Honda", model: "Accord", year: 1998};
delete mycar.make;
console.log("make" in mycar); // returns false
var trees = new Array("redwood", "bay", "cedar", "oak", "maple");
delete trees[3];
console.log(3 in trees); // returns false
console.log("toString" in {}); // returns true
console.log("length" in []); // returns true