1. Numeric expansion
var num = 0b11; Console.log (num); 3
var num = 0o11;console.log (num); 9
var num = 1.234;
Console.log (Math.trunc (num))//Kill the decimal point
Console.log (Math.sign (-0));//Determine whether the parameter is positive, negative, positive 0 or negative 0
Console.log (Math.hypot (3,4))//returns the square root of the sum of squares of all parameters (Pythagorean theorem)
2. Array expansion
var str = ' Xuniannian ';
var arr = array.from (str);//Convert the class array to a true array.
Console.log (arr);
var arr = array.of (1,2,3,4,5); the//array.of () method is used to convert a set of parameters to an array.
Console.log (arr);
var arr = new Array (5);
Console.log (Arr.length)
var arr = [];
Arr.find ()
Find the first array element that matches a condition
Parameters:
1. Callback function
2, the callback function within the direction of this
Iterates through the entire array, calls the callback function during traversal, and returns the element that is currently being traversed if the return value of the callback function is true.
Returns undefined if all elements do not meet the criteria
Arr.findindex ()
Find the position of the first qualified array element
Parameters:
1. Callback function
2, the callback function within the direction of this
Iterates through the entire array, calls the callback function during traversal, and returns the position of the array element if the return value of the callback function is true.
Returns 1 if all elements do not meet the criteria
Arr.fill ()
Used to populate an array
Parameters:
1, the content of the fill
2. Starting position
3. End Position
var arr = [1,2,3,4,5];
var n = arr.find (function (value,index) {
return value > 4;
})
Console.log (n);
var n = arr.findindex (function (value,index) {
return value > 5;
})
Console.log (n);
var arr = [1,2,3,4,5];
Arr.fill (6,2,4);
Console.log (arr);
Arr.length = 10;
Arr.fill (0);
3. Extension of objects
function fn (x, y) {
x + +;
y++;
return {
X:x,
Y:y
}
return {x, y};
}
Console.log (FN ())
var obj = {
Name: ' Momo ',
Showname:function () {
return this.name;
}
};
Console.log (Obj.showname ());
var sex = ' male ';
var person = {
Name: ' Momo ',
[Sex]:false,
[' Get ' + ' name '] (){
return this.name;
}
};
Console.log (Person.getname ());
Console.log (Person[sex])
ES6 Getting Started tutorial---Numeric extension array extensions and object extensions