SoFunction
Updated on 2025-03-01

Two more practical methods in Javascript es7

This article mainly introduces two more practical methods in es7. We will share them for your reference and learning. Let’s not say much below, let’s take a look at the detailed introduction together:

1. Operator (extendon operator)**

(2**3);//8
(4**4);//256
//Previous writing((2,3));//8
((4,4));//256

Not very simple yet, two * numbers can be used to exponentiate


es6 adds an include method for strings, and now uses the same as arrays.

l=[1,2,3]
(5)//false Same as an array

2. Character fill functions padStart and padEnd

padStart()Fill at the start part, return a string with the length given, fill the string with the given string, fill it with the expected length. Start at the left side of the string

padEnd starts filling from the right end of the string. The second parameter, you can actually use a string of any length.

('react'.padStart(10).length)   // "  react" is 10
('backbone'.padStart(10).length)   // " backbone" is 10


('react'.padEnd(10, ':-)'))   // "react:-):-" is 10
('backbone'.padEnd(10, '*'))   // "backbone**" is 10

two,:

let obj = { 
  x: 'xxx', 
  y: 1 
};
 (obj); // Print ['xxx', 1];
 let obj = ['e', 's', '8'];
 (obj); // Print ['e', 's', '8'];  
 ('es8'); // Print ['e', 's', '8'];  
 const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' };
 (obj); // Print ['yyy', 'zzz', 'xxx'];//Comments:If it's pure number Key value of type,Then the return value order is arranged from small to large according to the key value;

Summarize

The above is the entire content of this article. I hope that the content of this article will be of some help to your study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.