ES6 array extended string operators and new methods to traverse! ! !

The method is designed to allow us to study and work can be more convenient to manipulate data, arrays and strings!

The following code shows the beginning stages:

1. Extended operator

the console.log (... [l, 2,3 ])
 // These results output: l, 2,3 

the console.log ( . 1, ... [2,3,4],. 5 )
 // more output : 1,2,3,4,5

I can see in front of an array of three points, this method is ES6 expansion operator, which can be parsed to the array, so the array becomes the value

More convenient to get the data!

the console.log ([... [], 1 ])   
 // above Output: [1]

But the operator is extended behind an empty array will not have any effect.

 

2. String traversal

Code shows:

for (codePoint of the let 'over the seventh county, seat I was going to dismount' ) { 
      the console.log (codePoint); 
}

This code is the cycle of the output of each character, and each time the output of a character, Chinese character here is always output a!

This is the string traversal!

 

 

This sharing on here, remember attention!

I am a Han sauce, Bai Bai ┏ (^ 0 ^) ┛

Guess you like

Origin www.cnblogs.com/hansomeone/p/12115964.html