array splice split || string split slice silly you could not tell => finally figured out

The Array 
1. ARR
.slice ([ the begin [, End ]]): method returns a new array object, the object is a made  begin and  end the original array decision shallow copy (including  begin, not included end). Original array will not be changed.
    
    begin => start index
    end => index ended

. 1  var myFish = [ 'Angel', 'Clown', 'Mandarin', 'Sturgeon' ];
 2  var removed myFish.splice = (2, 0, 'Drum', 'Guitar' );
 . 3  
. 4  // after the operation myFish: [ "Angel", "Clown", "Drum", "Guitar", "Mandarin", "Sturgeon"] 
5  // removed element: [], no element is deleted

 

2. Array .splice ( Start [ , the deleteCount [ , ITEM1 [ , ITEM2 [ , ...]]]] ) method modified by deleting or replacing an existing array elements or adding new elements in place, and returns an array modified content. This method will change the original array
  
    start => starting index
    deletecount => the number of deleted

  var myFish = ['angel', 'clown', 'drum', 'mandarin', 'sturgeon'];
  var removed = myFish.splice(3, 1);
  
  @ myFish after operation: [ "angel", "clown", "drum", "sturgeon"]
  // removed element: [ "mandarin"]
  
  var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];
  var removed = myFish.splice(2, 0, 'drum', 'guitar');
  
 // 运算后的 myFish: ["angel", "clown", "drum", "guitar", "mandarin", "sturgeon"] // removed element: [], no element is deleted
 var myFish = ['angel', 'clown', 'mandarin', 'sturgeon'];  var removed = myFish.splice(2);  // 运算后的 myFish: ["angel", "clown"]  // 被删除的元素: ["mandarin", "sturgeon"]
 
 

String

  String. slice() The method to extract part of a string and returns a new string, and does not change the original string .

  slice() New string extraction include beginIndex, but are not included endIndex

  

var str1 = 'IS of The Morning upon US.', // str1 length is 23 length. 
    = str1.slice str2 (. 1,. 8 ),
    str3 = str1.slice(4, -2),
    str4 = str1.slice(12),
    str5 = str1.slice(30);
the console.log (str2); // Output: Morn of He 

the console.log (Str3); // Output: Morning IS U upon 
the console.log (str4); // Output: IS US upon. 
the console.log (str5); // output: ""

  String.split([separator[, limit]])

  

var myString = "Hello World. How are you doing?";
var splits = myString.split(" ", 3);

console.log(splits);

On example of the output:

["Hello", "World.", "How"]



var str = 'The quick brown fox jumps over the lazy dog.';

var words = str.split(' ');
console.log(words[3]);
// expected output: "fox"

var chars = str.split('');
console.log(chars[8]);
// expected output: "k"

var strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]

str.substring(indexStart[, indexEnd])方法返回一个字符串在开始索引到结束索引之间的一个子集, 或从开始索引直到字符串的末尾的一个子集

Extracting characters from indexStart to indexEnd (not included)

var anyString = "Mozilla";

// 输出 "Moz"
console.log(anyString.substring(0,3));
console.log(anyString.substring(3,0));
console.log(anyString.substring(3,-3));
console.log(anyString.substring(3,NaN));
console.log(anyString.substring(-2,3));
console.log(anyString.substring(NaN,3));

// 输出 "lla"
console.log(anyString.substring(4,7));
console.log(anyString.substring(7,4));

// 输出 ""
console.log(anyString.substring(4,4));

// 输出 "Mozill"
console.log(anyString.substring(0,6));

// 输出 "Mozilla"
console.log(anyString.substring(0,7));
console.log(anyString.substring(0,10));

 

 

 

 
 

Guess you like

Origin www.cnblogs.com/xiaomaotao/p/11704688.html