a1exlism
11/23/2017 - 2:16 AM

Base_prototype

Maybe Blog it?

var arr = [1, 'E', 'next', 'test', 4];

arr.slice(beginIndex[, endIndex]);                //  {{Shallow Copy}}
//  Minus:  only beginIndex = beginIndex + length;
//  beginIndex = undefined == 0

arr.slice(0, 1);      //  [1]
arr.slice(0, 2);      //  [1, 'E']
arr.slice(-2);        //  ["test", 4]

Array.prototype.slice.call(); //  Object-like


 
arr.splice(startIndex[, deleteCount[, item1, item2]])  //  {{Deep Copy}}
var origin;
var now;


/*
 *  SELECT from startIndex  *
 */

origin = [1, 'E', 'next', 'test', 4];

now = origin.splice(1);
//  origin: ["E", "next", "test", 4]
//  now   : [1]

now = origin.splice(-1);
//  origin: [4]
//  now   : ["E", "next", "test"]


/*
 *  INSERT at startIndex  *
 */
origin = [1, 'E', 'next', 'test', 4];
now = origin.splice(1, 0, 'newone');
//  origin: [1, "newone", "E", "next", "test", 4]
//  now:    []  yeah, a empty array

/*
 *  DELETE  from startIndex as deleteCount NUM*
 */
 
origin = [1, 'E', 'next', 'test', 4];
now = origin.splice(1, 1);
//  origin: ["E"]
//  now:    [1, "next", "test", 4]


/**TRANSFER**/
origin = [1, 'E', 'next', 'test', 4];

now = origin.splice(0);
//  origin: []
//  now:    [1, "E", "next", "test", 4]
var str = 'test123';
str.slice(indexStart[, indexEnd]);      //  Minus: sourceLength + indexStart

str.slice(0, 1);            //  e
str.slice(-2);              //  23

str.substr(start[, length]);            //  Minus: start == strLength + start

str.substr(1, 2);           //  es
str.substr(-1);             //  3
str.substr(-str.length, 2); //  t

str.substring(indexStart[, indexEnd]);  //  Except: indexStart<0 == 0 indexEnd>length-1 == length-1

str.substring(0, 1);        //  t
str.substring(-1);          //  test123
str.substring(1, 111);      //  est123