forEachRight
Invokes a function for each UTF-16 code unit in a string, iterating from right to left.
Usage
var forEachRight = require( '@stdlib/string/base/for-each-right' );
forEachRight( str, clbk[, thisArg ] )
Invokes a function for each UTF-16 code unit in a string, iterating from right to left.
function log( value, index ) {
console.log( '%d: %s', index, value );
}
forEachRight( 'Beep!', log );
/* =>
4: !
3: p
2: e
1: e
0: B
*/
The invoked function is provided three arguments:
- value: character.
- index: character index.
- str: input string.
To set the function execution context, provide a thisArg
.
function clbk() {
this.count += 1;
}
var str = '👉🏿';
var ctx = {
'count': 0
};
forEachRight( str, clbk, ctx );
var cnt = ctx.count;
// returns 4
Examples
var forEachRight = require( '@stdlib/string/base/for-each-right' );
function log( value, index ) {
console.log( '%d: %s', index, value );
}
forEachRight( 'presidential election', log );
forEachRight( 'Iñtërnâtiônàlizætiøn', log );
forEachRight( '🌷🍕', log );
forEachRight( '\uD834\uDD1E', log );