JavaScript count

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

Is it possible to use the .count() command in JavaScript?

I know how to write it in some codes, but I don't know if it's right or not to spit out the error Error: a.count is not a function in some codes;;

var a = '1234567';
var b = a.count('1');

Operation causes b = 1, failure if not


2022-09-20 11:29

1 Answers

In terms of the code you provided, the String.prototype.count() method must be predefined. Unfortunately, There is no such method defined. That's why the cord doesn't work.

vara = (Something String);
var = a.count('1'); // The meaning of the error that occurs here: count should be a function, but it is not! There seems to be no way for a to do count ("method")! Cannot proceed with this script ("script")! Error! Aborts execution.

"Can A 'command' be used for B?It has to change to the question, "Is 'Method A' available in B?" and so it has to lead to the process of finding B's specification and finding A there.

The desired action should not be called simply 'count', but 'occurrence count'. (*English count refers to the act of recklessly counting heads. For example, PHP's count($a) built-in function counts how many things are in $a.)

And the code you need is very diverse if you look up I hope your answer is helpful.

2022-09-20 11:29

If you have any answers or tips

© 2022 pinfo. All rights reserved.