User:Void/example.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// <nowiki>
// 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'
//</nowiki>