## page was renamed from JavascriptRegularExpression = Javascript = == Create an regular expression object == Replace string 'aaa' by 'xyz'. {{{#!highlight javascript var stringx = 'aaa bbb ccc'; var regexx = new RegExp('aaa','g'); stringx = stringx.replace( regexx , 'xyz' ); }}} == Delete property from object == {{{#!highlight javascript delete obj['propertyName']; }}} == Number of milliseconds since epoch == {{{#!highlight javascript var nrmillis = Date.now(); }}} == Foreach in array == https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach {{{#!highlight javascript function logArrayElements(element, index, array) { console.log("a[" + index + "] = " + element); } [2, 5, 9].forEach(logArrayElements); // logs: // a[0] = 2 // a[1] = 5 // a[2] = 9 }}} == Context with this and bind == https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind The bind() method creates a new function that, when called, has its this keyword set to the provided value, with a given sequence of arguments preceding any provided when the new function is called. {{{#!highlight javascript /*Constructor function*/ function Counter(){ this.counter=0; } Counter.prototype.run=function(){ console.log('counter:',this.counter); this.counter++; //recall run setTimeout(this.run.bind(this),1000); }; var c = new Counter(); setTimeout( c.run.bind(c) ,1000); // apply context of c to this }}}