Home > Article > Web Front-end > New APIs for Math, Number, String, Array, and Object
<code>Math.trunc(1.239); //1 Math.trunc(-3,1415926); //-2 Math.trunc(3.9); //3</code>
<code>Math.trunc("a"); //NaN Math.trunc(); //NaN Math.trunc(NaN); //NaN</code>
<code>Math.sign(11.22); //1 Math.sign(253); //1 Math.sign(0); //0 Math.sign(0.0); //0 Math.sign(-0.0); //-0 Math.sign(-0); //-0 Math.sign(-345); //-1 Math.sign(-2.983958); //-1 Math.sign('a'); //NaN Math.sign(); //NaN Math.sign(NaN); //NaN</code>
<code>Math.cbrt(8); //2 Math.cbrt(-64); //-4 Math.cbrt(-27);//3 Math.sign('a'); //NaN</code>
<code>Number.isInteger(25) // true Number.isInteger(25.0) // true Number.isInteger(25.1) // false Number.isInteger("15") // false Number.isInteger(true) // false </code>
<code>Number.isNaN(NaN) // true Number.isNaN(15) // false Number.isNaN('15') // false Number.isNaN(true) // false </code>
<code>var str="weirenshi"; str.includes("shi")//ture str.includes("ei")//ture str.includes("df")//false str.includes("dfghjk")//false</code>
<code>var str="weirenshi"; str.startsWidth("w")//ture str.startsWidth("we")//ture str.startsWidth("d")//false</code>
<code>var str="weirenshi"; str.endsWidth("i")//ture str.endsWidth("hi")//ture str.endsWidth("d")//false</code>
<code>"abc".repeat(3) // "abcabcabc" "wei".repeat(5) // "weiweiweiweiwei"</code>
<code>var arr=[1,2,3,4,5]; var ass=Array.from(arr);//[1,2,3,4,5]</code>
<code>Array.of(1, 2, 3);//[1,2,3]</code>
<code>[0, 0, 0].fill(7, 1) // [0,7,7] [0, 0, 0, 4, 6, 3, 4].fill(9, 3) // [0,0,9,9,9,9,9]</code>
<code>var aa = { a: 1 }; var qq = { b: 2 }; var zz = { c: 3 }; Object.assign(aa, qq, zz); target // {a:1, b:2, c:3} var ss={x:1,y:2}; var bb={}; Object.assign(ss,bb); bb.x=3; ss//x:1,y:2; bb//x:3,y:2;</code>
<code>var ff={x:1,y:2}; var vv={k:9,l:8}; var kk=Object.assign(ff,vv)//{x:1,y:2,k:9,l:8}</code>
The above is the detailed content of New APIs for Math, Number, String, Array, and Object. For more information, please follow other related articles on the PHP Chinese website!