Using Javascript and dingbats to tally the total number of checkmarks in a given string

Can you help me figure out how to count the checkmarks in a given string? The string I'm working with looks like this:

var myString = "one ✔ two ✔ three ✔"

I attempted using

myString.match(/✔/g) || []).length;
, but unfortunately, it's returning 0 (I think this is due to the fact that ✔ is considered a dingbat symbol).

I checked the unicode for "✔" and found it to be 2714. Is there a way to incorporate this into my expression?

Answer №1

After much troubleshooting, I successfully resolved my issue: To address the problem, I utilized the "unicode escape sequence" \u along with the 2714 unicode value:

.match(/\u2714/g) || []).length;

The root cause appeared to be related to a character encoding challenge (referenced in the feedback on my initial inquiry), but this approach appears to provide a reliable solution.

Answer №2

When performing a string match with unicode, there are no issues to worry about. By using the match method, you can obtain an array containing all matched elements. To determine the total number of matches, simply count the elements in the array. The following code snippet should help you achieve this:

myString.match(/✔/g).length

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What steps can I take to bring this idea to life in my gallery?

Currently, I am facing a roadblock while transitioning my design concept into actual code. My main concern lies with creating this art piece. Although the gallery is up and running with all the images in place, I'm encountering difficulties with the s ...

How to Align Text at the Center of a Line in Three.js

Exploring What I Possess. https://i.sstatic.net/nAtmp.png Setting My Goals: https://i.sstatic.net/svcxa.png Addressing My Queries: In the realm of three.js, how can I transform position x and y into browser coordinates to perfectly align text in th ...

Can someone provide instructions on how to convert base64 data to an image file

I'm utilizing the vue-signature Library but I am unsure how to download the base64 data that is generated as an image. Here is the link to the library: https://www.npmjs.com/package/vue-signature. I have gone through the documentation and noticed that ...

What is the best way to determine the property type dynamically in TypeScript based on the value of another property?

I have been working with Polymorphic relationships and currently have the following TypeScript interface defined: interface SubjectA {} interface SubjectB {} interface SubjectC {} enum SubjectType { SubjectA = 'Subject A', SubjectB = 'S ...

Rebooting Vue.js within the function

Snippet of code for showing an input field and focusing on it when mouseover occurs: Template: <span @mouseover="hoverOn('givenName')"> <input v-show="this.hovers['givenName']" ref="givenName" v-model="... and method ...

Interactive dropdown functionality based on user selection using Material UI

I am working on a project that involves implementing 3 dropdown components with Material UI. My goal is to disable the second and third dropdowns initially, and then enable them based on the selections made in the previous dropdowns. For instance, selectin ...

Determining the class condition using AngularJS ng-class

I am working with an HTML element that contains AngularJS directives: <div class="progress"> <span ng-repeat="timeRangeObject in timeRangeObjects" style="width: {{timeRangeObject.percentage}}%" ...

In my programming world, 'i' is a mysterious being - always undefined, except when it decides

Currently, I am utilizing Vue, Vuedraggable, and Vuetify in my project. I have encountered an issue where I am unable to use 'let' to define the index for my loop as it always returns undefined. Strangely, using 'var' instead of ' ...

Exploring the object structure received from AngularFire

Here is the Firebase query that I am running: var ref = new Firebase('https://<myfirebase>.firebaseio.com/companies/endo/status'); data = $firebaseObject(ref); console.dir(data); The object that I receive looks like this: d ...

Having difficulty retrieving values while using async-await

Utilizing the code below has been successful for me. I managed to retrieve the data in the spread (then), returning a http200 response. Promise.all([ axios({ method: 'post', url: 'https://oauth2.-arch.mand.com/oauth2/token&a ...

The application is experiencing extended loading times during production

After deploying my Angular 2 app on Heroku, I've noticed that it's taking a long time to load. Is there a way to bundle everything up instead of having all the scripts and stylesheets scattered across my index.html file? <html> <head> ...

Is it possible to remove generic T in typescript if the mysql result value is an array but generic T is not an array?

type User = { name: string email: string } This is the code snippet, import type { PoolConnection, RowDataPacket, OkPacket } from "mysql2/promise"; type dbDefaults = RowDataPacket[] | RowDataPacket[][] | OkPacket | OkPacket[]; type dbQuery& ...

Issue encountered when utilizing SwiftyJSON to parse JSON containing Unicode characters

When the API responds, this is the data I receive: 2015-08-31 7:29:45 [GDMNetManagerSMB.swift-228]: response: Optional(<NSHTTPURLResponse: 0x7fd6c507c6a0> { URL: ... } { status code: 200, headers { Age = 0; "Cache-Control" = "max-age ...

JavaScript: Issue with triggering form submit event

I'm facing an issue with getting the submit event to trigger on my form. I've added a submit button to the form and have included a script at the end of the body that references the necessary JavaScript functions for the form, but it's still ...

Executing a PHP script after successful execution of another script

tag, I am encountering the following script: Two minor issues: With the button being disabled after a click, it wont allow to click again if for instance an error is returned as shown above. It should only disable it after the input has been released $fo ...

React component's button has limited functionality when onClick event is triggered

I am facing an issue with creating a collapse menu in my React app. The onClick function for the button only works once. I have tried using a boolean variable to change its state when the button is clicked, but after the first click, the <a> tag beco ...

Managing Asynchronous Operations in Node.js

Hi everyone, I've hit a roadblock while trying to resolve an asynchronous problem in my Node.js code let isComplete = false; setTimeOut(() => { isComplete = true }, 1000) let count = 0; while(!isComplete) { console.log(count++) } I find that al ...

Find the location of $value in MongoDB where the timestamp is greater than or equal to JS

When attempting to find a nested element's existence and get a timestamp greater than a certain value, I'm encountering an issue: db.stats.find( { $and: [ { 'data.Statistics': {$exists: true} },{ timestamp: {$gte: 1} } ] } Although ...

The element 'mat-form-field' is unrecognized and not found in the document:

I'm facing an issue with my Angular app that utilizes Materials. I have imported MatFormFieldModule in my materials.module.ts file, but for some reason, it's not being recognized. All other material components are functioning properly except for ...

What steps can I take to resolve the Angular JS error message: [$injector:unpr]?

index.html <!DOCTYPE html> <html lang="en" ng-app="myApp"> <head> <meta charset="UTF-8"> <title>Angular JS</title> <script src="lib/angular.min.js"></script> ...