DEV Community

Cover image for Standard built-in objects in Java Script
Dakshata
Dakshata

Posted on • Edited on

Standard built-in objects in Java Script

The string in java script are used to represent and manipulate a sequence of characters.

Discussing about different standard built-in objects :-

Instance Method

  • String.prototype.charAt() - It returns a new string that consists of unit at the given index. JavaScript Demo: String.prototype.charAt() -
const name = 'Dakshata' console.log(name.charAt(4)) //output : 'h' 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.includes() - performs a case-sensitive search to determine whether a given string may be found within this string, returning true or false. JavaScript Demo: String.prototype.includes()
const sentence = 'I love tea' console.log(sentence.includes('love')) // output : true 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.indexOf() - It searches this string and returns the index of the first occurrence of the specified substring. JavaScript Demo: String.prototype.indexOf()
const search = ' My favorite language is JavaScript' console.log(search.indexOf('y')) // output : 2 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.replace() - It returns a new string with one, some, or all matches of a pattern replaced by a replacement. JavaScript Demo: String.prototype.replace()
const para = 'I live in India' console.log(para.replace('India' , 'Delhi')) //output : 'I live in Delhi' 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.slice() - It extracts a section of this string and returns it as a new string, without changing the original. JavaScript Demo: String.prototype.slice()
const str = 'I love cats and dogs' console.log(str.slice(2, -5)) // output : "love cats and" 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.split() - It takes a pattern and divides this string into an ordered list of substrings by searching for the pattern.
const str = ' I-am-learning-Reactjs ' const wordgap = str.split('-') console.log(wordgap[2]) // output: 'learning' 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.trim() - It removes whitespace from both ends of this string. JavaScript Demo: String.prototype.trim() -
const alpha = 'Fun and learn' console.log(alpha.trim()) //output: 'Fun and learn' 
Enter fullscreen mode Exit fullscreen mode
  • String.prototype.toLowerCase()/toUpperCase() - returns this string converted to lowercase/ uppercase respectively.
const sentence = 'I am happy' console.log(sentence.toUpperCase()) //output 'I AM HAPPY' 
Enter fullscreen mode Exit fullscreen mode

Still the list is not over many left to be discussed. Want to checkout more? Read this ECMAScript.

(っ◔◡◔)っ ♥ Show love and support ♥

Top comments (0)