String slice method only when receiving a return value of the parameter

A method for intercepting slice string string, when two transfer parameters when intercepts string and returns the contents taken, return the string

let str = 'You put his right hand on my left shoulder, I said the word softly sorry'

let res = str.slice(2,5);

console.log(res);     

Output result is: 'put right'

The first parameter indicates the starting position of interception, the second parameter represents the end position are taken, not the second parameter corresponding to the elements

What if the only pass a parameter to return it?

'123456'.slice(0)

All execution result is returned string '123456'

'123456'.slice(1)

Execution result is returned string '23456'

Only pass a parameter when in fact, is returned from the position of the element to the last element

What would pass a negative return it?

‘123456’.slice(-2)

Execution result is: '56'

Negative mass index retrieves starting from back to front

 

 

Guess you like

Origin www.cnblogs.com/zhang-jiao/p/11867350.html