Ejemplo 1: contar las apariciones de caracteres en una cadena javascript
var temp = "This is a string.";
var count = (temp.match(/is/g) || []).length;
console.log(count);
Output: 2
Explaination : The g in the regular expression (short for global) says to search the whole string rather than just find the first occurrence. This matches 'is' twice.
Ejemplo 2: JavaScript cuenta ocurrencias en cadena
function countOccurences(string, word) {
return string.split(word).length - 1;
}
var text="We went down to the stall, then down to the river.";
var count=countOccurences(text,"down"); // 2
Ejemplo 3: cadena javascript lentrh
var myString = "string test";
var stringLength = myString.length;
console.log(stringLength); // Will return 11 because myString
// is 11 characters long...
Ejemplo 4: longitud de javascript
var colors = ["Red", "Orange", "Blue", "Green"];
var colorsLength=colors.length;//4 is colors array length
var str = "bug";
var strLength=str.length;//3 is the number of characters in bug
Ejemplo 5: como obtener el recuento de letras en javascript
//when use length for string this will be return the count of charactor
//in string
$("#about_me_textarea").val().length
Ejemplo 6: valor de recuento de caracteres de a a b javascript
function count (string) {
var count = {};
string.split('').forEach(function(s) {
count[s] ? count[s]++ : count[s] = 1;
});
return count;
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)