Skip to main content

Posts

Showing posts with the label JavaScript

charCodeAt()

  JavaScript String charCodeAt() The  charCodeAt()  the method returns the Unicode of the character at a specified index in a string: The method returns a UTF-16 code (an integer between 0 and 65535). --------- <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The charCodeAt() method returns the unicode of the character at a given position in a string:</p> <p id="demo"></p> <script> let text = "HELLO WORLD"; document.getElementById("demo").innerHTML = text.charCodeAt(0); </script> </body> </html> ------------------------------------------ Result: JavaScript String Methods The charCodeAt() method returns the Unicode of the character at a given position in a string: 72

Substring

  JavaScript String substring() substring()  is similar to  slice() . The difference is that start and end values less than 0 are treated as 0 in  substring() . <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>The substring() method extract a part of a string and returns the extracted parts in a new string:</p> <p id="demo"></p> <script> let str = "Apple, Banana, Kiwi"; document.getElementById("demo").innerHTML = str.substring(7,13); </script> </body> </html> =============== Result: JavaScript String Methods The substring() method extracts a part of a string and returns the extracted parts in a new string: Banana

JavaScript String Methods

 JavaScript String Methods String methods help you to work with strings. String Methods and Properties Primitive values, like "John Doe", cannot have properties or methods (because they are not objects). But with JavaScript, methods, and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties. JavaScript String Length The length property returns the length of a string: ==================== <!DOCTYPE html> <html> <body>   <h2>JavaScript String Properties</h2>   <p>The length property returns the length of a string:</p>   <p id="demo"></p>   <script>   let text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";   document.getElementById("demo").innerHTML = text.length;   </script> </body> </html> ==================== Result: JavaScript String Properties The length property returns the length of a string: ...

JavaScript String Methods

Java Script  --------------------------  <!DOCTYPE html> <html> <body> <h2>JavaScript String Methods</h2> <p>Using String.split():</p> <p id="demo"></p> <script> let text = "Hello"; const myArr = text.split(""); text = ""; for (let i = 0; i < myArr.length; i++) {   text += myArr[i] + "<br>" } document.getElementById("demo").innerHTML = text; </script> </body> </html> ========= Result: JavaScript String Methods Using String.split(): H e l l o