count string value using map in javascript, return NaN -
I am trying to use a map to measure the duplicate string number in an array, my code: < / P>
var map = {}; Var Mearer = ["John", "John", "John", "Do", "Do", "Smith", "John", "Do", "Jo"]; (Var a = 0; a & lt; myarray.length; a ++) {if (map [mare [a]] == tap) {map [marta [a]] + = 1; } And {Map [Mareare [A]] = 1; }}
But when I do console.log (map);
gives it
object {John: NaN, Doe: Nain, Smith: Nain, Joe: Nain}
Why is this Nyan? ? I should have a similar result:
John: 4, DOE: 3, Smith: 1, Joe: 1
How can I do this? Thank you in advance.
In this case you null
strictly === < / Code> because
is not equal to
null
. Try it:
if (map [mare [a]] = tap) {
or simply:
(Map [Mareare [A]]) {
Comments
Post a Comment