- ES6 - Discussion
- ES6 - Useful Resources
- ES6 - Quick Guide
- ES9 - New Features
- ES8 - New Features
- ES7 - New Features
- ES6 - Browsers
- ES6 - Image Map
- ES6 - Debugging
- ES6 - Multimedia
- ES6 - Animation
- ES6 - Validations
- ES6 - Proxy API
- ES6 - Reflect API
- ES6 - Object Extensions
- ES6 - Error Handling
- ES6 - Modules
- ES6 - Promises
- ES6 - Maps And Sets
- ES6 - Classes
- ES6 - Collections
- ES6 - Iterator
- ES6 - HTML DOM
- ES6 - RegExp
- ES6 - Math
- ES6 - Date
- ES6 - Arrays
- ES6 - New String Methods
- ES6 - Symbol
- ES6 - Strings
- ES6 - Boolean
- ES6 - Number
- ES6 - Objects
- ES6 - Page Printing
- ES6 - Void Keyword
- ES6 - Dialog Boxes
- ES6 - Page Redirect
- ES6 - Cookies
- ES6 - Events
- ES6 - Functions
- ES6 - Loops
- ES6 - Decision Making
- ES6 - Operators
- ES6 - Variables
- ES6 - Syntax
- ES6 - Environment
- ES6 - Overview
- ES6 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
ES6 - Object Extensions
String extension
Some popular methods added to the String object in ES6 are −
Sr.No | Method & Description |
---|---|
1 |
determines whether a string begins with the characters of a specified string. Returns true or false |
2 |
determines whether a string ends with the characters of a specified string. Returns true/false |
3 |
determines whether one string may be found within another string |
4 |
constructs and returns a new string which contains the specified number of copies of the string on which it was called, concatenated together |
Regex extensions
In a regular expression, for example, /[A-Z]/g, the beginning and ending / are called depmiters. Anything after the closing depmiter 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.
Example
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.
Example
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
Number
Some popular methods added to the Number object in ES6 are −
Sr.No | Method & Description |
---|---|
1 |
method determines whether the passed value is a finite number. Returns true/false. |
2 |
returns true if the given value is NaN and its type is Number; otherwise, false. |
3 |
A floating-point number parsed from the given value. If the value cannot be converted to a number, NaN is returned. |
4 |
method parses a string argument and returns an integer of the specified radix or base. |
Math
Some popular methods added to the Math object in ES6 are −
Sr.No | Method & Description |
---|---|
1 |
function returns the sign of a number, indicating whether the number is positive, negative or zero. |
2 |
function returns the integer part of a number by removing any fractional digits. |
Methods of Array in ES6
The table given below highpghts the different array methods in ES6 along with the description.
Sr.No | Method & Description |
---|---|
1 |
shallow copies part of an array to another location in the same array and returns it without modifying its length. |
2 |
method returns a new Array Iterator object that contains the key/value pairs for each index in the array. |
3 |
method returns the value of the first element in the array that satisfies the provided testing function. Otherwise undefined is returned.. |
4 |
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. |
5 |
method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments. |
6 |
method creates a shallow copy from an array pke or iterable object. |
Object
Methods related to Object function are mentioned below in the table along with the respective description.
Sr.No | Method & Description |
---|---|
1 |
method determines whether two values are the same value |
2 |
method sets the prototype of a specified object to another object or null. |
3 |
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. |