Open In App

Fabric.js graphemeSplit() Method

Last Updated : 05 Jan, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

The graphemeSplit() method is used to divide a specified string in the user perceived single units that is each characters of the specified string will be converted into a single unit of string.

Syntax:

graphemeSplit(textstring)

Parameters: This method accepts a parameter as mentioned above and described below:

  • textstring: This parameter holds the string to divide.

Return Value: This method returns the array containing the graphemes that is the divided characters.

Example 1:

Javascript




<!DOCTYPE html>
  
<html>
  
<head>
   <script src=
   </script>
  
   <script type="text/javascript" src=
   </script>
  
   <script type="text/javascript" src=
   </script>
</head>
  
<body>
   <script type="text/javascript">
        console.log(fabric.util.string.graphemeSplit("GFG"));
        console.log(fabric.util.string.graphemeSplit("G F G"));
   </script>
  
</body>
  
</html>


Output:

["G","F","G"]
["G"," ","F"," ","G"]

Example 2:

Javascript




<!DOCTYPE html>
  
<html>
  
<head>
   <script src=
   </script>
  
   <script type="text/javascript" src=
   </script>
  
   <script type="text/javascript" src=
   </script>
</head>
  
<body>
   <script type="text/javascript">
       console.log("Using graphemeSplit() Function:");
       var value = "12ab";
       console.log(fabric.util.string.graphemeSplit(value));
  
       console.log("Without using graphemeSplit() Function:");
       var value="12ab";
       console.log(value);
   </script>
  
</body>
  
</html>


Output:

Using graphemeSplit() Function:
["1","2","a","b"]
Without using graphemeSplit() Function:
12ab


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads