ES6 - Object Extensions

Some popular methods added to the String object in ES6 are −
determines whether a string begins with the characters of a specified string. Returns true or false
determines whether a string ends with the characters of a specified string. Returns true/false
determines whether one string may be found within another string
constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together
In a regular expression, for example, /[A-Z]/g, the beginning and ending / are called delimiters. Anything after the closing delimiter is called a modifier. ES6 adds a new modifier /g where g stands for global. This match all instances of the pattern in a string, not just one.
The following example searches and returns all upper-case characters in the string.
<script>
   let str = 'JJavascript is Fun to Work , very Fun '
   let regex = /[A-Z]/g // g stands for global matches
   let result = str.match(regex);
   console.log(result)
</script>
The output of the above code will be as given below −
["J", "J", "F", "W", "F"]

Regular expression searches are case-sensitive. To turn-off case-sensitivity, use the /i modifier.
The following example performs a case insensitive global match. The example replaces fun with enjoyable.
<script>
   // /gi global match ignore case

   let str = 'Javascript is fun to Work , very Fun '
   let regex = /Fun/gi;
   console.log(str.replace(regex,'enjoyable'));
   console.log(str)
   console.log(str.search(regex))
</script>
The output of the above code will be as shown below −
Javascript is enjoyable to Work , very enjoyable
Javascript is fun to Work , very Fun
15

Some popular methods added to the Number object in ES6 are −
method determines whether the passed value is a finite number. Returns true/false.
returns true if the given value is NaN and its type is Number; otherwise, false.
A floating-point number parsed from the given value. If the value cannot be converted to a number, NaN is returned.
method parses a string argument and returns an integer of the specified radix or base.
Some popular methods added to the Math object in ES6 are −
function returns the sign of a number, indicating whether the number is positive, negative or zero.
function returns the integer part of a number by removing any fractional digits.
The table given below highlights the different array methods in ES6 along with the description.
shallow copies part of an array to another location in the same array and returns it without modifying its length.
method returns a new Array Iterator object that contains the key/value pairs for each index in the array.
method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned..
method fills all the elements of an array from a start index to an end index with a static value. It returns the modified array.
method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.
method creates a shallow copy from an array like or iterable object.
Methods related to Object function are mentioned below in the table along with the respective description.
method determines whether two values are the same value
method sets the prototype of a specified object to another object or null.
method is used to copy the values of all enumerable own properties from one or more source objects to a target object. It will return the target object.

    32 Lectures 
     3.5 hours 

 Sharad Kumar

    40 Lectures 
     5 hours 

 Richa Maheshwari

    16 Lectures 
     1 hours 

 Anadi Sharma

    50 Lectures 
     6.5 hours 

 Gowthami Swarna

    14 Lectures 
     1 hours 

 Deepti Trivedi

    31 Lectures 
     1.5 hours 

 Shweta
 Print
 Add Notes
 Bookmark this page