code 的魔法
String.prototype.split() The split() method divides(分配) a String into an ordered list of substrings(?), puts these substrings into an array, and returns the array. The division(分割) is done by searching for a pattern(型態); where the pattern is provided as the first parameter(變數、參數) in the method's call. String to Array ex: const str = 'The quick brown fox jumps over the lazy dog.'; const words = str.split(' '); console.log(words); // expected output: Array ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."] =========== Array.prototype.slice() The slice() method returns a shallow(淺的) copy of a portion(部分) of an array into a new array object selected from start to end (end not included) where start and end represent(表現) the index of items in that array. The original array will not be modified(做改動). Array to New Array "array.slice(start, end) end not included" ex: const animals = ['ant', 'bison', 'camel', 'duck', 'elephant']; console.log(animals.slice(2)); // expected output: Array ["camel", "duck", "elephant"] console.log(animals.slice(2, 4)); // expected output: Array ["camel", "duck"]