let str="aaa"; console.log("+"+str+"+");//+aaa+ //padStart()用於頭部補全, //數字定義字符串的長度 let aaa=str.padEnd(5); console.log("+"+aaa+"+");//+aaa + //padEnd()用於尾部補全 let bbb=str.padStart(5); console.log("+"+bbb+"+");//+ aaa+
返回一個數組,獲取對象的值json
let obj={ name:'aa', age:3 } console.log(Object.values(obj));// ["aa", 3] let arr=["a","b"]; console.log(Object.values(arr));//["a", "b"]
返回一個數組,其元素是與[key, value]直接找到的可枚舉屬性對應的數組object。屬性的順序與經過手動循環對象的屬性值給出的順序相同。數組
let obj={ name:'aa', age:3 } console.log(Object.entries(obj));//[["name","aa"],["age","3"]]
用來獲取對象的鍵名瀏覽器
let obj={ name:'aa', age:3 } console.log(Object.keys(obj));//["name","age"];
function fn(a,b,){ console.log(123); } fn(1,2,) //數組高低版本都支持,不會報錯,只會顯示undefined let arr2=[1,2,3,] console.log(arr2[2]);//3 console.log(arr2[5]);//undefined //對象同理 var obj22={a:1,b:2,}