1.arry.slice(start,end) var a=[1,2,3,4,5,6]; var b=a.slice(0,3); //[1,2,3] The last bit is not taken, the original array a remains unchanged 2.string.slice(start,end) var a="I am a boy"; var b=a.slice(0,6) //The last digit of "I am a" is not taken, the original array a remains unchanged 3.array.splice(start,deleteCount,item...) var a=['a','b','c']; var b=a.splice(1,1,'e','f'); //a=['a','b','f','c'],b=['b'] replace the value of a, which returns the deleted value 4.string.split(separator,limit) var a="0123456"; var b=a.split("",3) //b=['0','1','2'] 5.arrayObject.push(newelem1,newelem2,....) var a=[1,2,3,4,5]; va b=a.push(6,7); //a=[1,2,3,4,5,6,7],b=7 The original array is changed, return the changed length 6.arrayObject.pop() var a=[1,2,3,4,5]; var b=a.pop(); //a=[1,2,3,4],b=5 Change the original array and return the last value that was deleted 7.arrayObject.shift() var a=[1,2,3,4,5]; var b=a.shift() //a=[2,3,4,5],b=1 Change the original array and return the first value that was deleted 8.arrayObject.unshift() var a=[1,2,3,4,5]; var b=a.unshift(0) //a=[0,1,2,3,4,5],b=6 Change the original array and return the first value that was deleted 9.arrayObject.concat(array1,array2,...) var a=[1,2,3,4,5]; var a2=['a','b','c']; var a3=['d',6]; var b=a.concat(a2,a3) //a,a2,a3 do not change, b=[1, 2, 3, 4, 5, "a", "b", "c", "d", 6] return new array 10.arrayObject.sort(sortby) var a=[1,2,3,4,5]; a.sort(function(a,b){ return b-a; }) //a=[5, 4, 3, 2, 1] Sort and reorganize the original array 11.arrayObject.reverse() var a=[1,2,3,4,5]; a.reverse() //a=[5, 4, 3, 2, 1] reverse continuation 12.object.toSource //!!!!!!!!!!! only supported by Gecko function employee(name,job,born) { this.name=name; this.job=job; this.born=born; } var bill=new employee("Bill Gates","Engineer",1985); console.log(bill.toSource()) //({name:"Bill Gates", job:"Engineer", born:1985}) 13.booleanObject.toString var boo = new Boolean(true); console.log(boo.toString()); //returns the string true Return Value Returns the string "true" or "false" based on the primitive boolean value or the value of the booleanObject object. If the object on which the method is called is not a Boolean, an exception TypeError is thrown. 14.object.toLocalString var d = new Date() document.write(d.toLocaleString()) //The local time converts the Date object to a string and returns the result. 15.booleanObject.valueOf() var boo = new Boolean(false); console.log(boo.valueOf()); //return false The return value is a primitive boolean value of booleanObject. If the object on which the method is called is not a Boolean, an exception TypeError is thrown.
slice,splice,split,push,pop,shift,unshift,concat,sort,reverse...
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=324805892&siteId=291194637
Recommended
Ranking