User:Void/example.js

// // Example javascript (Basically a reference sheet) // For the love of all that is holy DO NOT LOAD // TODO: add $.ajax, $.getJSON, various mw.whatever methods

// Strings var stringy = 'This is a string'; stringy.length; // is 16 stringy.indexOf('is'); // is 2 stringy.lastIndexOf('is'); // Is 5 stringy.slice(5,7); // is 'is' stringy.slice(stringy.lastIndexOf('is'), stringy.indexOf(' ', stringy.lastIndexOf('is'))); // Is 'is' stringy.replace(/is/g, 'no'); // is 'Thno no a string' stringy.replace(/is/, 'no'); // is 'Thno is a string' stringy.replace(/\sis\s/,' no '); // is 'This no a string'

// Arrays var arr = ['this', 'is', 'an', 'array']; arr.length; // is 4 arr[0]; // is 'this' arr.join(' '); // is 'this is an array'

// Objects var obj = { info: 'This is an object', more: function{return this.info;} }; obj.info; // is 'This is an object' obj.more; // is 'This is an object'

//